Can't have WelcomeController and User::WelcomeController ? n

I have a top level controller and a nested controller with the same
name WelcomeController.

It works fine in development mode.

Then in production mode, it says there are no actions for that
controller, and plops out this error…

/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/
inflector.rb:250: warning: toplevel constant WelcomeController
referenced by User::WelcomeController

Is’nt that the whole point of modules, there basically a namespace to
keep this from being a problem ???

I faced the exactly same problem.

This is caused by ruby’s language specification,
rather than by the implementation of ActiveSupport.

When you accessed User::WelcomeController,
it is expected that missing of User::WelcomeController raises
and Name Error exception. ActiveSupport handles this exception.
However, if ::WelcomeController was already loaded, Ruby would
treat it as User::WelcomeController, and raise no exception,
and ActiveSupport couldn’t work.

For example, following code refers Foo::Bar which doesn’t exsist,
but this code don’t results in NameError exceptions.

class Foo
end

class Bar
end

Foo::Bar

To solve this problem, I added codes like followings:

class User
Dependencies.load_missing_constant self, :WelcomeController

This results in User::WelcomeController to be always loaded
when User is loaded(User will be loaded when you try to access
User::WelcomeController).

If Ruby supports options or flags to resolve name scopes
strictly, it will work well for this problem.
But I’m not sure whether Ruby does.

[email protected] wrote:

I have a top level controller and a nested controller with the same
name WelcomeController.

It works fine in development mode.

Then in production mode, it says there are no actions for that
controller, and plops out this error…

/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/
inflector.rb:250: warning: toplevel constant WelcomeController
referenced by User::WelcomeController

Is’nt that the whole point of modules, there basically a namespace to
keep this from being a problem ???

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs