ruby

Ruby Array#puts not using overridden implementation?

I am using Ruby 1.8.6 for the following code: # Create an array and override the #to_s on that object thing = [1,2,3] def thing.to_s 'one' end print "Using print: " print thing puts puts "Using puts: " puts thing Output: Using print: one Using puts: 1 2 3 So thing is an Array and I have overridden thing#to_s. print seems to us...

Auditable NDA Solution

Just started at a place and, currently, they ask folks to fax in NDA. They want to (possibly) move toward doing something electronically on their web site. It seems they aren't too keen on the checkbox ("I agree") approach and would like to keep an audit trail. Ahem, they even brought up digital signatures which I have no experience impl...

Installing Rails ERROR: could not find rails locally or in a repository

I've been poking around the internet looking for a solution on this one... with no luck.. I'm new to rails... If anyone has an idea, I'd love to hear it. Much appreciated! I enter: LW:src liamwright$ sudo gem install rails --include-dependencies And Get: INFO: `gem install -y` is now default and will be removed INFO: use --ignore-...

Whats a good ruby idiom for breaking up a large class into modules?

I have a large class with lots of methods and it's starting to get a bit unorganized and hard to navigate. I'd like to break it up into modules, where each module is a collection of class and instance methods. Perhaps something like this: UPDATE: I've now realized that this is a pretty poor example. You probably wouldn't want to move va...

How do I configure capistrano to use my rvm version of Ruby

Does anybody know how I can tell capistrano to use my default rvm version of ruby for on the server I am pushing to. It insists on using the system version. Is it even possible? ...

Retrieve all options from select tag after submitting

Hello, I have a slight problem with getting the options within the select tag. Some background information; This is a report, and as such the select options will vary depending on what is stored on the DB depending on some conditions. So, I'm using observe field to get the selected option, BUT, I need to get all the options because I...

How to improve the way I browse an array with .each while trying to keep track of the index ("i") using Ruby?

Let's say I'm doing a simple .each but I still want to keep the position in the loop, I can do: i = 0 poneys.each do |poney| #something involving i #something involving poney i = i + 1 end This doesn't look very elegant to me. So I guess I could get rid of the .each: for i in 0..poneys.size-1 do #something involving i end ...

rails polymorphic association (legacy database)

I am using a legacy database, so i do not have any control over the datamodel. They use a lot of polymorphic link/join-tables, like this create table person(per_ident, name, ...) create table person_links(per_ident, obj_name, obj_r_ident) create table report(rep_ident, name, ...) where obj_name is the table-name, and obj_r_ident is ...

Generating helper function module

I a writing a DSL to generate parsers for bioinformatics flat files. I would like to let the user define helper functions in block and then include the function in the parsing context object. I would like to use a syntax like: rules = Rules.new do helpers do def foo() #... end def bar( baz ) #... end ...

How to get the row numbers when I using render in RoR?

I use this code to generate the td tag format: <%= render(:partial => "cart_item", :collection => @cart.items) %> And this is the _cart_item.html.erb: <tr> <td class="column-left"><%=h cart_item.title %></td> <td> x <%= cart_item.quantity %></td> <td class="column-right">$ <%= cart_item.price %></td> </tr> But I want t...

Rails Complex nested form - random issue

I know this is a complete long shot, but I thought I would give it a try. I have an issue when submitting an extremely large nested form to the update action. This issue is completely random, and when it happens I can not get it to reoccur even using the same dataset from when it happened. When the issue happens it seems that the parame...

How do I change an attribute value in a model?

I have the following script ActiveRecord::Base.establish_connection(:adapter => 'mysql', :database => 'development', :username => 'appAccount', :password => '------', :socket => '/tmp/mysql.sock') class ProcessQueue < ActiveRecord::Base end The tutorial I'm using claims the following should work. updateQ = ProcessQueue.find(:all, :...

Can I modify RoR CRUD behavior?

I know that the RoR CRUD is very easy to use. But I want the generate program do something special that normal CRUD. I don't want "Delete" in my apps, all the record only can make as "delete" instead of actually delete. So, I want to add a column -- "status" automatically when the Create is generated, and I want to change the "Delete" be...

How can I merge two hashes without overwritten duplicate keys in ruby?

I'm new in Ruby, so, sorry if this is an easy question :) Do you know an easy or elegant way to merge two arrays without overwriting duplicate keys? I mean if the key is present in the original array i don't want to change anything in the original array... ...

When the input is from a pipe, does STDIN.read run until EOF is reached?

Sorry if this is a naïve question, but let's say I have a Ruby program called processor.rb that begins with data = STDIN.read. If I invoke this program like this cat textfile.txt | processor.rb Does STDIN.read wait for cat to pipe the entire textfile.txt in? Or does it assign some indeterminate portion of textfile.txt to the data vari...

Ruby Rical Timezone problem.

I'm using Ruby Rical to basically generate an icalendar as a response to an original icalendar specifing that I'm attending (accepting) the invitation. I can generate the response correctly but I'm having a problem with timezones, basically if I let RiCal infer the correct Timezone, it works correctly depending on the TimeZone String sp...

find . -type f in ruby

I want to grab a list of all the files under a particular directory. Dir.glob works great, but there doesn't seem to be a way to limit results to just files (excluding directories). Heres's what I have right now: files = Dir.glob('my_dir/**/*').reject { |f| File.directory?(f) } Is there a more elegant way to accomplish this? ...

Sorting/Paginating/Filtering Complex Multi-AR Object Tables in Rails

I have a complex table pulled from a multi-ActiveRecord object array. This listing is a combined display of all of a particular user's "favorite" items (songs, messages, blog postings, whatever). Each of these items is a full-fledged AR object. My goal is to present the user with a simplified search, sort, and pagination interface. The ...

How to distribute ruby software?

Hi i am serching for the best way to distribute ruby software (can be open or commercial) to clients: - with less software installed on client (only ruby interpreter) - without less user interaction for updates Any idea? I can use gem but it needs to install rubygems and not fit with commercial software. ...

Basic ruby array code: Testing if an array has a specific integer

I'm trying to test if an array has a specific integer in it. Right now I'm using this test; def admin? current_user.role_ids == [1,2] || current_user.role_ids == [2] || current_user.role_ids == [1,2,5] end The code works, but I'd prefer to just test for the integer "2" rather than explicitly write out every possible combination...