ruby-on-rails

Rails: FasterCSV - Unique Occurences

I have my CSV file imported as such: records = FasterCSV.read(path, :headers => true, :header_converters => :symbol) How can I get the unique occurences of my data? For instance, here some sample data: ID,Timestamp test,2008.12.03.20.26.32 test,2008.12.03.20.26.38 test,2008.12.03.20.26.41 test,2008.12.03.20.26.42 test,2008.12.03.20....

In Rails, how do you use RESTful controllers with Haml?

I'm getting started on figuring out how to use RESTful design. I have this action: # GET /feedback_messages # GET /feedback_messages.xml def index page = params[:page] page ||= 1 @feedback_messages = FeedbackMessage.paginate( :all, :page => page, :per_page => 20, :order => 'updated_at' ) respond_to do |format|...

Ruby on Rails: hash.each {} issues

Here is my code: records_hash = records[:id].inject({}) { |result,h| if result.has_key?(h) result[h] += 1 else result[h] = 1 end result } @test2 = records_hash.each{|key,value| puts "#{key} is #{value}"} My output should look like this: bozo is 3 bubba is 4 bonker is 5 But it renders on the page (<%= @test2 %>) as ...

Ruby on Rails running on a vps slice

What are the major gotchas and tricks when running Rails on a small slice (256MB)? What is the best server setup for cramped quarters? Passenger, Nginx, Mongrel? What is the best background task processor in this kind of environment? What do you need to watch out for? I'd love to hear the stories of people who have done this and bump...

In rails, whether to use form helpers or not to?

In rails, is it recommended to use form helpers? Internally, everything boils down to plain html then why not write the html directly? Performance will obviously be better in writing direct html than using helpers. Is using form helpers like a convention or something that rails developers must follow? ...

Better way of returning the values of a column in Active Record?

Quick one, but thought I'd ask. Is there a better way of getting the column values from a model's column than something like this? Item.count(:all, :group => 'status').reject! { |i, e| i.blank? }.collect { |i,e| i} ...

Weird Behavior when using between? method for dates

Open up a Rails console and enter this: 2.weeks.ago.between? 2.weeks.ago, 1.week.ago Did it give you true or false? No really, try it a few more times and it will give you different answers. Now, I'm thinking that because we're comparing 2.weeks.ago with 2.weeks.ago, the time between evaluating the two statements is causing this beha...

Overriding id on create in ActiveRecord

Is there any way of overriding a model's id value on create? Something like: Post.create(:id => 10, :title => 'Test') would be ideal, but obviously won't work. ...

Ruby on Rails: Common pitfalls/gotchas

There is a similar question about Ruby in general but I am soon to be starting out using Ruby on Rails to develop a website or two. What are the common pitfalls/gotchas that are specific to Rails. ...

OpenID authentication goes into strange error loop (Ruby on Rails, ruby-openid, open_id_authentication)

I've been using OpenID for my site for a while, and everything has been working fine. However, recently I've been seeing some strange errors in the error logs. Apparently, everything works fine for the user, and they're able to log in. However, in the background, the OpenID library seems to go into a loop that causes a bunch of errors...

Generate PDF from Rails

The Ruby On Rails Wiki lists a couple of libraries that facilitate PDF generation in Rails. I need to print out address labels (in letter format, thus 12-15 addresses per page) and cannot decide which one to use. Any recommendations? ...

Ruby: Math functions for Time Values

How do I add/subtract/etc. time values in Ruby? For example, how would I add the following times? 00:00:59 + 00:01:43 + 00:20:15 = ? ...

How do I run Rails integration tests without dropping DB contents?

I've written some integration tests that I'd like to run against a copy of my prod database before I push to production. This lets me test all of my routes are still correct, all of the pages render without errors and some of the multipage workflows work as expected. When I run the integration tests it drops the database I've loaded and...

Rails: how do you access RESTful helpers?

I'm trying to work through this guide to Rails routing, but I got stuck in section 3.3: Creating a RESTful route will also make available a pile of helpers within your application and then they list some helpers like photos_url, photos_path, etc. My questions: Where can I find the complete list of helpers that is "made available?...

Mongrel hangs

Hi all, I'm running into a problem in a Rails application. After some hours, the application seems to start hanging, and I wasn't able to find where the problem was. There was nothing relevant in the log files, but when I tried to get the url from a browser nothing happened (like mongrel accept the request but wasn't able to respond). ...

How to pass a flexible number of ids into a controller in Rails?

I'd like to display a comparison page so user can compare the properties of several objects in my database. Any number of objects can be compared. I'd also like it to be bookmarkable (so a 'get'). How should I structure my URL / route for the controller? Something like /foo_compare/1_5_22 where I split the ids into 1, 5 and 22 in the ...

JRuby on Rails deployment

I need to host a JRuby on Rails app on Mongrel. The problem is that I need to support mutual authentication. I know that I could just host it behind a Apache with mod_proxy use mod_ssl to pass the cred or part of the cred as a request header to rails. But I want the whole stack to be Java. Is there a Java application server that can do m...

Session Problem in Rails 2.2 "ActionController::InvalidAuthenticityToken in User#register"

Hi everyone, I am reading and learning from this very cool book Railspace - Building Social Networking sites. I understand everything but i am stuck with the sessions section. Its something i would really like to get under my belt and would appreciate any help! Ok so here is the error i get: ActionController::InvalidAuthenticityTo...

How do I "copy unless later version exists" in Capistrano?

I want to protect my database.yml file by keeping it out of version control. Thus, I have two tasks in my Capistrano deploy recipe: task :copy_db_config do # copy local config file if it exists and is more # recent than the remote one end task :symlink_db_config do run "ln -nfs #{shared_path}/config/database.yml #{release_path}/...

FasterCSV: Read Remote CSV Files

I can't seem to get this to work. I want to pull a CSV file from a different webserver to read in my application. This is how I'd like to call it: url = 'http://www.testing.com/test.csv' records = FasterCSV.read(url, :headers => true, :header_converters => :symbol) But that doesn't work. I tried Googling, and all I came up with was...