Rails 2: Model.find(1) gives ActiveRecord error when id 1 does not exist

This is the expected behavior. I think David explains this the best himself, so here is a quote from Ruby, S., Thomas, D. & Hansson, D.H., 2009. Agile Web Development with Rails, Third Edition Third Edition., Pragmatic Bookshelf (p.330). When you use a finder driven by primary keys, you’re looking for a particular record. You … Read more

undefined method `source_index’ for Gem:Module (NoMethodError)

I just ran into this problem myself while trying to upgrade an older Rails app from REE 1.8.7 to 1.9.3-p385. Oddly, Ruby 1.9.3-p327 works just fine. What it came down to was ruby-1.9.3-p385 had installed RubyGems version 2.0.2 for me, and 1.9.3-p327 has RubyGems v1.8.23 installed. Gem.source_index has been deprecated for a while, but since … Read more

Rails ActiveRecord date between

Just a note that the currently accepted answer is deprecated in Rails 3. You should do this instead: Comment.where(:created_at => @selected_date.beginning_of_day..@selected_date.end_of_day) Or, if you want to or have to use pure string conditions, you can do: Comment.where(‘created_at BETWEEN ? AND ?’, @selected_date.beginning_of_day, @selected_date.end_of_day)