Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Possible bug with uncountable inflections and namedspace routes?

#4226

If i have an uncountable inflection (in this case "content"), and i was then to add a namespace with a resource named after that inflection to correspond to a model (of that very same name!), e.g:

e.g.

  routes.rb
  ---------
  namespace :admin do
    resources :content
  end

  content_controller.rb
  ---------------------
  class Admin::ContentController < ApplicationController
    def new
      @content = Content.new
    end
  end

I get the following:

1) Error: test_get_new(Admin::ContentControllerTest):
NoMethodError: undefined method new' for Admin::Content:Module<br/>

/Users/omarqureshi/Sites/Ruby191/content-menage/app/controllers/admin/content_controller.rb:8:in `new'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/implicit_render.rb:4:in `send'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/base.rb:153:in `process_action'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/rendering.rb:11:in `process_action'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:433:in `_run__77664824__process_action__2035442755__callbacks'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:423:in `_run_process_action_callbacks'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/callbacks.rb:88:in `run_callbacks'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/callbacks.rb:17:in `process_action'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/instrumentation.rb:29:in `block in process_action'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications/instrumenter.rb:18:in `instrument'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active_support/notifications.rb:53:in `instrument'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/instrumentation.rb:28:in `process_action'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/rescue.rb:8:in `process_action'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/base.rb:123:in `process'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/abstract_controller/rendering.rb:41:in `process'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/metal/testing.rb:12:in `process_with_new_base_test'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/test_case.rb:350:in `process'
/Users/omarqureshi/.rvm/gems/ruby-1.9.1-p378%rails3/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/actionpack/lib/action_controller/test_case.rb:288:in `get'
/Users/omarqureshi/Sites/Ruby191/content-menage/test/functional/admin/content_controller_test.rb:6:in `block in <class:ContentControllerTest>'

I definitely do NOT have a module called Admin::Content defined in my app or in any gems that I am using (just haml and pg). Fiddling with the resource - e.g. changing it from resources :content to resources :contents, works - however, that is NOT what I am after here, trying to define singular and plural path names doesn't seem to do anything either.

I believe this bug is different from https://rails.lighthouseapp.com/projects/8994/tickets/3930-uncounta...

Reported by omarqureshi · March 19th, 2010 @ 12:00 AM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: High

Activity

  1. omarqureshi
    omarqureshi
    • Tag set to inflections, rails3, routing, uncountable

    March 19th, 2010 @ 12:03 AM

  2. José Valim
    José Valim

    This is completely odd. Can you try to isolate the issue? In the meanwhile, I recommend you to use ::Content instead of Content.

    March 27th, 2010 @ 01:56 PM

  3. José Valim
    José Valim
    • Milestone cleared.
    • Assigned user set to José Valim

    And please try "defined?(Admin::Console)" in rails console. Maybe the module is defined somewhere else?

    March 28th, 2010 @ 06:27 AM

  4. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • State changed from new to needs-more-info

    March 29th, 2010 @ 01:13 AM

  5. omarqureshi
    omarqureshi

    defined?(Admin::Content) in the console from when I was trying to debug it returned false - what I had done is moved work on the app back to 2.3.5 temporarily which worked fine.

    I will move it back to 3 beta and stick on github as proof of concept.

    March 29th, 2010 @ 01:34 PM

  6. Rolf Bjaanes
  7. Rolf Bjaanes
    Rolf Bjaanes

    Uhm, seems as this is regarding uncountables with two or more words in them, might be wrong.

    April 3rd, 2010 @ 06:34 PM

  8. Andrew White
    Andrew White

    Okay, I've managed to track down what's happening here. Basically autoload_module! in AS::Dependencies is creating a module dynamically because autoloadable_module? is returning true due to app/views being in the load_paths array.

    More people would have hit this problem except for the fact that the app/models path is earlier in the load_paths array and controllers are normally plural and model names singular.

    I'm assuming that app/views has been added to load_paths for a reason?

    It's easy to reproduce this:

      $ rails testapp
      ...
      $ cd testapp
      $ rails generate controller projects
      ...
      $ rails console
      >> Projects.class # Should raise NameError: uninitialized constant Projects
      => Module
    

    April 5th, 2010 @ 10:15 AM

  9. José Valim
    José Valim
    • State changed from needs-more-info to open

    Right, thanks for finding out the reason Andrew! You've been doing an excellent work on other tickets as well. I'm on this one!

    April 5th, 2010 @ 10:56 AM

  10. Repository
  11. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to High

    October 15th, 2010 @ 11:01 PM