This project is archived and is in readonly mode.

#1458 ✓resolved
ronin-15560 (at lighthouseapp)

Namespaced resources fail in production when controllers are not namespaced

Reported by ronin-15560 (at lighthouseapp) | November 24th, 2008 @ 12:44 PM | in 3.0.2

If you have this route definition:


map.namespace :time do |time|
    time.resources :tags, :controller => 'tags'
end

and the controller is defined as


class TagsController < ApplicationController

in app/controllers/tag_controller.rb, Rails 2.2 fails in production mode (NOT in development mode), with the following exception:


(ArgumentError) "Object is not missing constant TagsController!"

Here's the backtrace:


APP_ROOT/vendor/rails/activesupport/lib/active_support/dependencies.rb:419:in `load_missing_constant'
APP_ROOT/vendor/rails/activesupport/lib/active_support/dependencies.rb:77:in `const_missing'
APP_ROOT/vendor/rails/activesupport/lib/active_support/dependencies.rb:89:in `const_missing'
APP_ROOT/vendor/rails/activesupport/lib/active_support/dependencies.rb:95:in `send'
APP_ROOT/vendor/rails/activesupport/lib/active_support/dependencies.rb:95:in `const_missing'
APP_ROOT/vendor/rails/activesupport/lib/active_support/inflector.rb:352:in `constantize'
APP_ROOT/vendor/rails/activesupport/lib/active_support/inflector.rb:351:in `each'
APP_ROOT/vendor/rails/activesupport/lib/active_support/inflector.rb:351:in `constantize'
APP_ROOT/vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
APP_ROOT/vendor/rails/actionpack/lib/action_controller/routing/route_set.rb:388:in `recognize'
APP_ROOT/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:182:in `handle_request'
APP_ROOT/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:110:in `dispatch_unlocked'
APP_ROOT/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:123:in `dispatch'
APP_ROOT/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in `synchronize'
APP_ROOT/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in `dispatch'
APP_ROOT/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:132:in `dispatch_cgi'

I've no idea if this is supposed to work in the first place, but in development mode everything works just fine and is peachy.

Comments and changes to this ticket

  • Dwayne Macgowan

    Dwayne Macgowan November 26th, 2008 @ 05:04 AM

    I'm getting the same problem. In slightly different context, not related to routing.

    I've got my model

    
    class Persona < ActiveRecord::Base
     ...
    end
    

    And I've got in another model the following:

    
    class Coeficiente < ActiveRecord::Base
     ...
     def private.db_field(class_name)
      table = eval "#{class_name}.table_name"
     end
     ...
      db_field(Persona)
     ...
    end
    

    here's my backtrace

    
    0  	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb  	419  	in `load_missing_constant'
    1 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb 	77 	in `const_missing'
    2 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb 	89 	in `const_missing'
    3 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb 	95 	in `send'
    4 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb 	95 	in `const_missing'
    5 	/home/kshemac/kshema/demo/releases/20081125002850/app/models/coeficiente.rb 	79 	in `persona_es_alumna_sql'
    6 	/home/kshemac/kshema/demo/releases/20081125002850/app/models/instructor.rb 	8 	
    7 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb 	27 	in `gem_original_require'
    8 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb 	27 	in `require'
    9 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb 	155 	in `require'
    10 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb 	262 	in `require_or_load'
    11 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb 	221 	in `depend_on'
    12 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb 	133 	in `require_dependency'
    13 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb 	368 	in `load_application_classes'
    14 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb 	367 	in `each'
    15 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb 	367 	in `load_application_classes'
    16 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb 	365 	in `each'
    17 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb 	365 	in `load_application_classes'
    18 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb 	185 	in `process'
    19 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb 	112 	in `send'
    20 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb 	112 	in `run'
    21 	./config/environment.rb 	9 	
    22 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb 	27 	in `gem_original_require'
    23 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb 	27 	in `require'
    24 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb 	153 	in `require'
    25 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb 	521 	in `new_constants_in'
    26 	/opt/ruby-enterprise-1.8.6-20080810/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb 	153 	in `require'
    27 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/railz/application_spawner.rb 	252 	in `preload_application'
    28 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/railz/application_spawner.rb 	212 	in `initialize_server'
    29 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/utils.rb 	181 	in `report_app_init_status'
    30 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/railz/application_spawner.rb 	201 	in `initialize_server'
    31 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	166 	in `start_synchronously'
    32 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	135 	in `start'
    33 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	112 	in `fork'
    34 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	112 	in `start'
    35 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/railz/application_spawner.rb 	177 	in `start'
    36 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/railz/framework_spawner.rb 	270 	in `handle_spawn_application'
    37 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/railz/framework_spawner.rb 	263 	in `synchronize'
    38 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/railz/framework_spawner.rb 	263 	in `handle_spawn_application'
    39 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	317 	in `__send__'
    40 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	317 	in `main_loop'
    41 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	168 	in `start_synchronously'
    42 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	135 	in `start'
    43 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	112 	in `fork'
    44 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	112 	in `start'
    45 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/railz/framework_spawner.rb 	87 	in `start'
    46 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/spawn_manager.rb 	218 	in `spawn_rails_application'
    47 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/spawn_manager.rb 	213 	in `synchronize'
    48 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/spawn_manager.rb 	213 	in `spawn_rails_application'
    49 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/spawn_manager.rb 	122 	in `spawn_application'
    50 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/spawn_manager.rb 	247 	in `handle_spawn_application'
    51 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	317 	in `__send__'
    52 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	317 	in `main_loop'
    53 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/lib/passenger/abstract_server.rb 	168 	in `start_synchronously'
    54 	/usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.3/bin/passenger-spawn-server 	46 	
    
  • Pratik

    Pratik March 12th, 2009 @ 05:30 PM

    Is this still an issue ? Could you please submit a failing test case ? http://guides.rails.info/contrib... should be helpful.

    Thanks

  • ...

    ... May 19th, 2009 @ 07:04 PM

    Still getting this problem...

    routes.rb

    map.namespace :account do |account|

    account.resources :sponsorships
    account.resource :profile, :controller => "users"
    

    end

    A login form with :url => account_profile_path generates this error:
    @@@Processing ApplicationController#create (for ... at 2009-05-19 10:57:44) [POST] Parameters: {"user"=>{"password_confirmation"=>"[FILTERED]", "password"=>"[FILTERED]", "email"=>"*****@gmail.com"}, "commit"=>"Register", "action"=>"create", "controller"=>"account/users"}

    NameError (uninitialized constant Account::UsersController):@@@

    No idea why it's even processing ApplicationController... :S

    Again, works fine in development, breaks in production... :(

    ~Levi Figueira

  • ...

    ... May 19th, 2009 @ 07:08 PM

    NOTE: Why can't I edit a comment? Or at least preview it... :(

    Let's hope this one comes out "readable"... :/

    Still getting the same problem...

    # routes.rb
      map.namespace :account do |account|
        account.resources :sponsorships
        account.resource :profile, :controller => "users"
      end
    

    A login form with :url => account_profile_path generates this error:
    @@@ Processing ApplicationController#create (for ... at 2009-05-19 10:57:44) [POST] Parameters: {"user"=>{"password_confirmation"=>"[FILTERED]", "password"=>"[FILTERED]", "email"=>"*****@gmail.com"}, "commit"=>"Register", "action"=>"create", "controller"=>"account/users"}

    NameError (uninitialized constant Account::UsersController):

    
    No idea why it's even processing ApplicationController... :S
    Again, works fine in development, breaks in production... :(


    ~Levi Figueira
  • ...
  • Daniel Guettler

    Daniel Guettler May 25th, 2009 @ 04:32 PM

    @Thomas, you need to reset the namespace not the controller in your nested resource so it should look like this otherwise it will assume you have a Time::TagsController:

    {{{ map.namespace(:time) do |time|

    time.resources :tags, :namespace => ''
    

    end }}}

  • Daniel Guettler

    Daniel Guettler May 25th, 2009 @ 04:33 PM

    Ah sorry wrong markup:

      map.namespace(:time) do |time|
        time.resources :tags, :namespace => ''
      end
    
  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • ximus

    ximus May 26th, 2010 @ 01:26 PM

    Some behavior under rails 3 beta3.

  • Andrew White

    Andrew White June 28th, 2010 @ 09:27 AM

    • Assigned user set to “Andrew White”
    • State changed from “new” to “resolved”
    • Milestone cleared.
    • Importance changed from “” to “”

    This will now be possible with the 3.0 RC

      scope(:path => 'time', :as => :time) do
        resources :tags
      end
    
  • Jeremy Kemper

    Jeremy Kemper October 15th, 2010 @ 11:01 PM

    • Milestone set to 3.0.2

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages