Forum: Ruby on Rails Rails 2.1.2 to 2.3.2 problems

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bharat R. (Guest)
on 2009-03-25 23:09
I just installed Rails 2.3.2 and tried to upgrade my test app from
2.1.2.  After installing Rails 2.3.2, I simply changed the gem version
in my environment.rb file in config directory as shown below:

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION

The server refuses to start and I get the following stacktrace:

=> Booting Mongrel
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:416:in
`initialize_database': undefined method `configurations=' for
ActiveRecord::Base:Class (NoMethodError)
        from
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:141:in
`process'
        from
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in
`send'
        from
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in
`run'
        from /home/bruparel/exp/pizzeria-3/config/environment.rb:13
        from
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
        from
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
        from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in
`require'
        from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:521:in
`new_constants_in'
        from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in
`require'
        from
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:84
        from
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
        from
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
        from script/server:3


Change it back to 2.1.2 and I am fine.  Is there something that is
missing?  I do a rails -v and it shows that 2.3.2 is installed as shown
below:

bruparel@bcr-d810:~$ rails -v
Rails 2.3.2
bruparel@bcr-d810:~$

Thanks for your time.

Bharat
Conrad T. (Guest)
on 2009-03-25 23:14
(Received via mailing list)
On Wed, Mar 25, 2009 at 2:09 PM, Bharat R. <
removed_email_address@domain.invalid> wrote:

> => Booting Mongrel
>        from
>
>        from
> Change it back to 2.1.2 and I am fine.  Is there something that is
> missing?  I do a rails -v and it shows that 2.3.2 is installed as shown
> below:
>
> bruparel@bcr-d810:~$ rails -v
> Rails 2.3.2
> bruparel@bcr-d810:~$
>
> Thanks for your time.
>
> Bharat


Hi, did you update your configs?

rake rails:update

-Conrad
Bharat R. (Guest)
on 2009-03-25 23:32
Hello Conrad,
you wrote:
>
> Hi, did you update your configs?
>
> rake rails:update
>
> -Conrad

No. I had not done that, but after reading your reply I did, but I get
the same error :) as can be seen below:

bruparel@bcr-d810:~/exp/pizzeria-3$ cd config/
bruparel@bcr-d810:~/exp/pizzeria-3/config$ vi environment.rb
bruparel@bcr-d810:~/exp/pizzeria-3/config$ cd ..
bruparel@bcr-d810:~/exp/pizzeria-3$ rake rails:update
(in /home/bruparel/exp/pizzeria-3)
/home/bruparel/exp/pizzeria-3/app/controllers/application.rb has been
renamed to
/home/bruparel/exp/pizzeria-3/app/controllers/application_controller.rb,
update your SCM as necessary
bruparel@bcr-d810:~/exp/pizzeria-3$ ruby ./script/server
=> Booting Mongrel
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:416:in
`initialize_database': undefined method `configurations=' for
ActiveRecord::Base:Class (NoMethodError)

Note that I edited the environment.rb to set Rails Gems to 2.3.2, but it
does not work.

Bharat
Bharat R. (Guest)
on 2009-03-26 00:38
Hello Conrad,
I am making good progress towards resolving this, but am not there
entirely.  Following is my abbreviated environment.rb file.  Note that I
have commented out the RAILS_GEM_VERSION line so that the latest rails
2.3.2 is loaded.

# Specifies gem version of Rails to use when vendor/rails is not present
#RAILS_GEM_VERSION = '2.1.2' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|

  # Add additional load paths for your own custom dirs
  config.load_paths += %W( #{RAILS_ROOT}/app/form_builders )

  config.time_zone = 'UTC'

  config.action_controller.session = {
    :session_key => '_pizzeria_session',
    :secret      =>
'1cac89a5ef8e67d30b297648243baee84a52d16dbbf11690733a73c825da43c327a6552f9498d0fe2ecf29cbc09ebf6115102fe3d26f969909f005dc1da39e09'
  }


  require "#{RAILS_ROOT}/lib/active_record_extensions.rb"

end

if I comment out the last require
"#{RAILS_ROOT}/lib/active_record_extensions.rb"

statement as shown below:

# require "#{RAILS_ROOT}/lib/active_record_extensions.rb"

and restart the server then it boots and everything works fine except
where I need the functionality contained in
lib/active_record_extensions.rb file which is as follows:

module ActiveRecord

  class Base
    def self.search(search, current_page, search_field)
      if search.blank?
        paginate(:all, :page => current_page || 1, :per_page => 5)
      else
        paginate(:all, :conditions => ["#{search_field} LIKE ?",
"%#{search}%"], :order => 'name',
          :page => current_page || 1, :per_page => 5)
      end
    end
  end

end

Why does Rails 2.3.2 have a problem with it when 2.1.2 does not?  The
error messages are very misleading and point to some problem with
database when there is none?
Bharat R. (Guest)
on 2009-03-26 01:36
Figured it out:

Rails 2.3 has a problem with requiring any files within the initializer
block as shown below.

Rails::Initializer.run do |config|

  require "#{RAILS_ROOT}/lib/active_record_extensions.rb"

end

Instead, it wants you to put your require statement outside the block as
shown below:

Rails::Initializer.run do |config|

   .....


end
require "#{RAILS_ROOT}/lib/active_record_extensions.rb"

This works.  Why is it so?  I do not know.  If someone can explain this,
I would appreciate it.

Thanks.

Bharat
Frederick C. (Guest)
on 2009-03-26 01:44
(Received via mailing list)
On Mar 25, 11:36 pm, Bharat R. <removed_email_address@domain.invalid>
wrote:
> Figured it out:
>
> Rails 2.3 has a problem with requiring any files within the initializer
> block as shown below.
>
> Rails::Initializer.run do |config|
>
>   require "#{RAILS_ROOT}/lib/active_record_extensions.rb"
>
> end

ActiveRecord is not loaded at this point. The right place for this
sort of stuff is in an initializer (see
http://www.spacevatican.org/2008/11/21/environment...
for ways where putting it at the bottom of environment.rb can go
wrong).

Fred
Bharat R. (Guest)
on 2009-03-26 02:07
Thanks Fred.  Here is what I did after reading the link that you posted:

I created the config/initializers/load_lib_dir.rb with the following
line of code:

Dir.glob( "#{ RAILS_ROOT }/lib/*.rb" ).each { |f| require f } <-- thanks
Greg.

I guess, I have some homework to do on the initializers.

Regards,

Bharat
QJGui (Guest)
on 2009-03-31 04:27
(Received via mailing list)
Please use
rake rails:update

After you update your rails version, you should check your app, the
config file and the plugins.
Most time ,the errors are happening in the config file(config/
environments/....) and the plugins.

On Mar 26, 5:09 am, Bharat R. <removed_email_address@domain.invalid>
Moin H. (Guest)
on 2009-11-19 21:26
> ActiveRecord is not loaded at this point. The right place for this
> sort of stuff is in an initializer (see
> http://www.spacevatican.org/2008/11/21/environment...
> for ways where putting it at the bottom of environment.rb can go
> wrong).
>
> Fred

+1
thanks Fred :)
This topic is locked and can not be replied to.