1

My environment:

  • Rails 3.2.8
  • Ruby 1.9.3p194
  • Fedora 16 x86_64

This problem seems specific to Rails Engines.

It seems that when using the HttpHelpers in a Rails Engine's routes file, I get "uninitialized constant Controller" when accessing a route via a browser. But, if I use a URL matcher in the Engine's routes file, it routes correctly.

Here's how I created a failing example:

$ rails plugin new my_engine --mountable
$ cd my_engine
$ rails g controller things index
$ rails s -p 3005

The controller generator uses the HttpHelpers#get method by default, so at this point the Rails Engine's config/routes.rb file looks like:

MyEngine::Engine.routes.draw do
  get "things/index"

end

And, the test/dummy application's config/routes.rb file looks like:

Rails.application.routes.draw do

  mount MyEngine::Engine => "/my_engine"
end

So, I should be able to hit http://locahost:3005/my_engine/things/index and see the Things#index view from the Engine. But, instead in the browser I see:

Routing Error

uninitialized constant ThingsController

If I manually change the Engine's config/routes.rb file to:

MyEngine::Engine.routes.draw do
  #get "things/index"
  match "things/index" => "things#index"

end

... and hit http://locahost:3005/my_engine/things/index, I see the correct Things#index view.

I noticed that when I use the HttpHelpers#get method in the Engine's config/routes.rb file, and run rake routes from the test/dummy directory, I see:

$ rake routes
my_engine  /my_engine MyEngine::Engine

Routes for MyEngine::Engine:
things_index GET /things/index(.:format) things#index

But, if I change the Engine's config/routes.rb file to use the URL matcher method, I see:

$ rake routes
my_engine  /my_engine MyEngine::Engine

Routes for MyEngine::Engine:
things_index  /things/index(.:format) my_engine/things#index

Notice that when using the URL matcher, the controller and action are correctly namespaced under the engine. While, when using the HttpHelpers#get, the controller and action seem to be non-namespaced.

So, my question: Am I doing something wrong here? Or, is this a bug?

Note: I searched the rails issues and didn't see anything directly related to this. Though I did see several other engine and routing issues.

0 Answers0