I just got hit by this famous error again. And I am not the only one:

Now, I know I should put my patches where my mouth is. And that’s exactly what I’m trying to do here. My application is on the 1.2 branch, and I get this error if I have the Response Logger plugin loaded. Trying again with Edge Rails, I again get the error. If I try with WEBrick or Mongrel, same error. Loading the console produces the same error. Using Windows or Linux changes nothing: same error.

The exact backtrace is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ ruby script\console
Loading development environment.
./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:249:in `load_missing_constant': Expected ./script/../config/../config/../vendor/plugins/response_logger/lib/response_logger.rb to define ResponseLogger (LoadError)
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:452:in `const_missing'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:464:in `const_missing'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:260:in `load_missing_constant'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:452:in `const_missing'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:260:in `load_missing_constant'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:452:in `const_missing'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:260:in `load_missing_constant'
        from ./script/../config/../config/../vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:468:in `const_missing'
         ... 14 levels...
        from C:/ruby/lib/ruby/1.8/irb/init.rb:250:in `load_modules'
        from C:/ruby/lib/ruby/1.8/irb/init.rb:21:in `setup'
        from C:/ruby/lib/ruby/1.8/irb.rb:54:in `start'
        from C:/ruby/bin/irb.bat:20

In this application, I am using Engines, along with LoginEngine. You really need the right version of Engines with the right version of Rails for things to work out well: Rails 1.2 requires Engines 1.2.

Rails Engine configuration woes

November 3rd, 2005

I learned a nice one today. If you use Rails Engines and you want to configure your environments differently, you can’t do this:

1
2
3
module LoginEngine
  config :salt => 'test'
end
1
2
3
module LoginEngine
  config :salt => 'a-long-and-complicated-salt'
end

Engines.start :login
If you do that, you’ll get the following backtrace:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ ruby script\server
./script/../config/../vendor/rails/railties/lib/initializer.rb:178:in
`load_environment': undefined method `config' for
Rails::Initializer::LoginEngine:Module (NoMethodError)
       from ./script/../config/../vendor/rails/railties/lib/initializer.rb:150:in `load_environment'
       from ./script/../config/../vendor/rails/railties/lib/initializer.rb:147:in `silence_warnings'
       from ./script/../config/../vendor/rails/railties/lib/initializer.rb:147:in `load_environment'
       from ./script/../config/../vendor/rails/railties/lib/initializer.rb:73:in `process'
       from ./script/../config/../vendor/rails/railties/lib/initializer.rb:36:in `send'
       from ./script/../config/../vendor/rails/railties/lib/initializer.rb:36:in `run'
       from ./script/../config/../config/environment.rb:10
       from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'
       from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
       from ./script/../config/../vendor/rails/railties/lib/commands/server.rb:52
       from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'
       from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
       from script/server:3
What is happening is that Rails loads the environment file before the Rails Engine plugin is initialized. The solution ? Do everything in config/environment.rb:
1
2
3
4
5
6
7
8
9
10
module LoginEngine
  case RAILS_ENV
  when 'development', 'test'
    config :salt, "test"
  when 'production'
    config :salt, "another-long-and-complicated-salt"
  end
end

Engines.start :login

Rails Engine Released

November 1st, 2005

Over on the Rails mailing list, James Adams reports the initial release of Rails Engines.

What are engines ? They are plugins, more or less, except they also bundle controllers, views, partials, models and everything else you’d usually need in a component.

In fact, Rails Components could very well be implemented using Rails Engines.

I wonder how routes are handled. Can engines provide their own routes, or must the engine user define the routes he wants ? Gotta try that login_engine and see for myself.

 

Search

A picture of me

I am François Beausoleil, a Ruby on Rails coder. During the day, I work on XLsuite. At night, I am interested many things. Read my biography

Tags

(3) (1) (0) (2) (1) (1) (2) (2) (1) (2) (1) (2) (1) (2) (1) (1) (1) (1) (2) (14) (1) (1) (1) (1) (2) (1) (1) (2) (0) (1) (2) (1) (3) (1) (1) (1) (1) (1) (1) (0) (3) (2) (1) (2) (2) (1) (3) (2) (8) (8) (9) (12) (1) (1) (3) (1) (1) (1) (1) (1) (1) (2) (2) (2) (1) (1) (3) (1) (3) (1) (0) (21) (1) (1) (0) (1) (1) (1) (21) (23) (1) (1) (13) (1) (1) (2) (3) (1) (1) (4) (1) (2) (3) (0) (1) (7) (3) (1) (5) (5) (2) (2) (2) (4) (6) (7) (1) (0) (1) (1) (2) (2) (1) (4) (12) (2) (1) (2) (4) (1) (1) (1) (2) (8) (2) (3) (2) (2) (1) (3) (1) (1)

Links

Projects I work on

Categories

Archives