Legacy version of the Ruby on Rails web development framework.
Questions tagged [ruby-on-rails-2]
746 questions
209
votes
11 answers
Rails ActiveRecord date between
I need to query comments made in one day. The field is part of the standard timestamps, is created_at. The selected date is coming from a date_select.
How can I use ActiveRecord to do that?
I need something like:
"SELECT * FROM comments WHERE…

rtacconi
- 14,317
- 20
- 66
- 84
132
votes
5 answers
undefined method `source_index' for Gem:Module (NoMethodError)
I'm running a Rails 2.3.5 application and upon running script/server I am shown the following:
./script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module…

noodleboy347
- 1,355
- 2
- 9
- 8
71
votes
1 answer
Routing with an optional parameter
I added in the route file:
map.show_book "/show_book/:name/year/:year", :controller => "book", :action => "show_version"
I also added:
map.show_book "/show_book/:name", :controller => "book", :action => "show_version"
to show the latest book…

Alessandro De Simone
- 4,085
- 6
- 28
- 41
65
votes
2 answers
Failing to access environment variables within `database.yml` file
I have the following developement section of my development.yml file:
development:
adapter: postgresql
host: localhost
database: testtb
username: app_user
password: ENV['APP_USER_POSTGRES_PASSWORD'] <= Troublesome line
When I open a…

jefflunt
- 33,527
- 7
- 88
- 126
61
votes
5 answers
How I can check if an object is null in ruby on rails 2?
I want to check when my object @objectname is not equal to null to show the values of the @objectname else to show that no values found.
I tried this:
<% if (@objectname != null) then %>
but I'm getting an error.

George Panayi
- 1,768
- 6
- 26
- 42
37
votes
5 answers
Rails Flash.now not working
I have a view from which I make an ajax request to the controller and after the action is successfully completed I initialize the flash.now[:notice]. But after the control goes back to the view. I don't happen to see the flash…

Manjunath Manoharan
- 4,567
- 6
- 28
- 43
31
votes
8 answers
Rails 2: Model.find(1) gives ActiveRecord error when id 1 does not exist
I am using Rails 2.3.5 and in that if I give Model.find(1) and if 1 is not in the database, it returns ActiveRecord error. Should it just be returning nil as in the case of Model.find_by_column('..')?

rubyprince
- 17,559
- 11
- 64
- 104
30
votes
7 answers
mysql2.so: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory
I am trying to run a Rails two app with Ubuntu 10.04 server, sphinx, myql2 version 0.2.7 and percona server 5.5 (Myslql 5.5). mysql2 in irb works ok, I can connect to the db. this rails 2 app is working in another Centos server with MySql 5.1. When…

rtacconi
- 14,317
- 20
- 66
- 84
30
votes
3 answers
How do you clear a single entry from a ruby on rails session?
In ruby on rails when doing session[:foo] = nil it leaves an entry named :foo in the session object. How can you get rid of that single entry from the session object?

Jim Soho
- 2,018
- 2
- 21
- 25
28
votes
9 answers
Rails: get #beginning_of_day in time zone
I have a default time zone setup for the rails application.
And an instance of the Date object.
How can I get make Date#beginning_of_day to return the beginning of the day in the specified time zone, but not my local timezone.
Is there any other…

Bogdan Gusiev
- 8,027
- 16
- 61
- 81
23
votes
7 answers
ActiveRecord::Base Without Table
This came up a bit ago ( rails model attributes without corresponding column in db ) but it looks like the Rails plugin mentioned is not maintained ( http://agilewebdevelopment.com/plugins/activerecord_base_without_table ). Is there no way to do…

Dan Rosenstark
- 68,471
- 58
- 283
- 421
22
votes
5 answers
ActiveRecord Count to count rows returned by group by in Rails
I looked around and couldn't find any answers to this. All answers involved counts that did not use a GROUP BY.
Background:
I have a paginator that will take options for an ActiveRecord.find. It adds a :limit and :offset option and performs the…

J.Melo
- 331
- 1
- 3
- 9
22
votes
2 answers
Upgrading from Rails 2.3.8 to 4.0
I am running an application on Rails 2.3.8. I am planning to upgrade it to Rails 4.0 (which is in RC). What will be the easiest way for me to do this? Do I need to first upgrade to Rails 3.x?
Note: in my current implementation, I am using starling…

nit
- 321
- 2
- 4
20
votes
6 answers
How to monkey-patch code that gets auto-loaded in Rails?
I'm monkey-patching a Rails engine with something like:
SomeClass.class_eval do
# ...
end
The first time I hit the web site, on development mode at least, it works, but the second time it's like my patch never existed. I presume it's Rails…

Pablo Fernandez
- 279,434
- 135
- 377
- 622
20
votes
3 answers
Force SSL using ssl_requirement in Rails 2 app
I have a Rails application which need to run under SSL. I tried ssl_requirement but seems I have to type in all the actions in every controllers.
Is there any method that I can add a before_filter in application controller with ssl_requirement, so…

Victor Lam
- 3,646
- 8
- 31
- 43