ruby

accessing children of children tables in Rails

I have a "tree-like" structure to my database in an app I am writing so that: training has_many class_times and class_time has_many reservations Is there a way to look up all reservations under a a given training? I could iterate through all of class times/add a foreign key, of course, but for some reason I have this little voice...

Remove ":" from the ruby on rails time_select helper output?

I want to remove the ":" from the output of the rails time_select helper. The helper seems to output this automatically when the minutes select box is built. Any ideas? Thanks! ...

FileTest.exists? issue with ruby on rails

Hi, I am trying to check if a file exists in my rails application. I am running ruby 1.8.6 and rails 2.1.2 with windows XP. So, the problem is that the FileTest.exists? method doesn't seem to be working. I have simplified the code to this point : if FileTest.exists?("/images/header.jpg") render :text => "yes" else render...

Ruby: Reading PDF files

I'm looking for a fast and reliable way to read/parse large PDF files in Ruby (on Linux and OSX). Until now I've found the rather old and simple PDF-toolkit (a pdftotext-wrapper) and PDF-reader, which was unable to read most of my files. Though the two libraries provide exactly the functionality I was looking for. My question: Have I ...

Ruby: Want a Set-like object which preserves order

... or alternatively an Array which prevents duplicate entries. Is there some kind of object in Ruby which: responds to [], []= and << silently drops duplicate entries is Enumerable (or at least supports find_all) preserves the order in which entries were inserted ? As far as I can tell, an Array supports points 1, 3 and 4; while a Se...

Does LDAP (or any Ruby client library for LDAP) support batch calls?

I'm thinking no, but hope to be corrected. http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol i.e. i'm simply looking to a batch read of ~1000 users via one query, instead of making ~1000 separate queries. Update: Okay, it helps to read the spec: http://tools.ietf.org/html/rfc2254 : ) ...

Ruby IDEs: any worth looking at?

I currently use TextMate for all my Rails development, and I like it very much, but I wonder if I'm missing anything by not using an IDE. Has anyone switched from using TextMate or another powerful text editor to a Ruby IDE? Am I missing anything? ...

Business rules for calculating prices

The business I work for is an on-line retailer, I'm currently working on a project that among other things involves calculating the customer prices for products. We will probably create a service that looks something like... public interface IPriceService { decimal CalculateCustomerPrice(ISupplierPriceProvider product); } public inte...

Really odd method in application

I just came across an odd method in some Ruby code, and I'm wondering if I'm missing something fundamental. It looks like this: def funny !funny end What would this possibly return? ...

How do you remove fields with Activewarehouse-etl?

I'm parsing a csv file and trying to send it to a table with fewer fields than the original csv file. How do I remove those extraneous commas that are left over if I set the extra fields to nothing? Here's the original csv format: columns => id,first_name,last_name,phone,fax sample row => 1,ben,tomas,5555555,6666666 Here's the final ...

growing binary payload in ruby

I am new to ruby and looking for a way to create a "payload" of random binary data. def payload_grow(payload_stack) payload = payload_stack valid_chars = ("a".."f").to_a + ("0".."9").to_a length = valid_chars.size hex_code = "" hex_code << valid_chars[rand(length-1)] hex_code payload = payload + '0x' + hex_code + hex_code ...

What Ruby programming book should I read first?

I'm am an experienced developer in other languages like C#, VB.net and C++, but a real newbie in Ruby. What Ruby book do you think should I read first? ...

How to create activerecord style validations outside of activerecord?

Hi, I am working on a testing framework for the software that my company writes. Our product is web based and After I run a RESTful request I want to process the results. I want to be able to have activerecord type validations in each command class so that after it is run the results are automatically tested against all the "validation...

How can I parse a string that contains wildcards and character classes in Ruby?

I would like to write a script that takes one argument that might look like this: abc(ag)de* a, b, c are literal characters. (ag) means "an 'a' or a 'g'". * means any one letter or number. I want the script to create an Array of all the possible strings the input could represent. (The purpose is to check if they're available domain...

Where is it legal to use ruby splat operator?

Splats are cool. They're not just for exploding arrays, although that is fun. They can also cast to Array and flatten arrays (See http://github.com/mischa/splat/tree/master for an exhaustive list of what they do.) It looks like one cannot perform additional operations on the splat, but in 1.8.6/1.9 the following code throws "unexpected ...

Escaping HTML entities in the URL of a rails remote_function

Some content in my page is loaded dynamically with the use of this code : javascript_tag( remote_function( :update => agenda_dom_id, :url => agenda_items_url(options), :method => :get ) ) When it outputs in the browser, it comes out as this : new Ajax.Updater('agenda', 'http://localhost:3000/agenda_items?company=43841&amp;amp;history...

What's the best way to talk to a database while using Sinatra?

As I understand it, the Sinatra framework, unlike Rails, does not provide an ORM. In that case, how do you talk to a DB in a Sinatra app? Or is Sinatra only for apps that don't use a DB? ...

Rails POST, PUT, GET

After I generate a scaffold, Rails gives me the ability to POST to items.xml which will create a new item. A GET to items.xml will simply list them all. Where does Rails specify which method in the controller (create or index, respectively) will be called, based on the type of action I am performing? More specifically, POST calls method...

Connecting to MS SQL Server with JRuby

I'm working on a project that involves some scripting and data storage. The database that I have available to me is MS Sql Server and it is on a windows platform. Despite this I'm looking to leverage Ruby to write the script, specifically JRuby. There are a couple of reasons for this I would like to leverage Prawn to create pdfs ...

Complex relationships in Ruby - display data across many tables

Hi, I have designed an application consisting of 20+ tables, and utilizing Ruby on Rails. I am using an authentication system for users to login. I want to display to the user, when he logs in, information related to him that can be found across many tables, between these tables there are all the possible relationships. How can I accomp...