Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10362 (reopened defect)

Opened 5 months ago

Last modified 3 months ago

[PATCH] map.resource docs incorrectly mention :plural option

Reported by: nwiger Assigned to: core
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords: docs
Cc:

Description

I have an AccountController (notice "Account" not "Accounts") that has this in routes.rb:

map.resource :account, :plural => 'account',

:member => { :login => :post, :logout => :post }

This no longer works in Rails 2.0 RC2. It looks for "AccountsController" (plural)

I've tried debugging it, but am not an EdgeRails expert. Here's the stack trace:

NameError (uninitialized constant AccountsController):

/vendor/rails/activesupport/lib/active_support/dependencies.rb:266:in `load_missing_constant' /vendor/rails/activesupport/lib/active_support/dependencies.rb:453:in `const_missing' /vendor/rails/activesupport/lib/active_support/dependencies.rb:465:in `const_missing' /vendor/rails/activesupport/lib/active_support/inflector.rb:257:in `constantize' /vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb:148:in `constantize' /vendor/rails/actionpack/lib/action_controller/routing.rb:1423:in `recognize' /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:170:in `handle_request' /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:115:in `dispatch' /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi' /vendor/rails/actionpack/lib/action_controller/dispatcher.rb:9:in `dispatch'

that appears irrelevant...

Attachments

resource_docs_no_plural_option.trunk.diff (1.7 kB) - added by kampers on 02/08/08 18:03:30.
resource_docs_no_plural_option.2-0-stable.diff (1.7 kB) - added by kampers on 02/08/08 18:03:42.

Change History

02/02/08 08:22:32 changed by kampers

  • status changed from new to closed.
  • resolution set to wontfix.

The convention in Rails 2.0 is to use a plural name for the controller, even if you're mapping a singular resource. This is because you could map to the same controller using several routings, one of which could be plural. So it's more consistent to just always use the plural. For example, you might have people, each of whom owns one hat, and a store that sells many hats:

map.resources :people do |person|
  person.resource :hat
end

map.resources :stores do |store|
  store.resources :hats
end

If you want to override this and use AccountController anyway, just use the :controller option (not the :plural option).

02/07/08 21:42:31 changed by gryn

  • status changed from closed to reopened.
  • resolution deleted.

That's all well and good, but the documentation says :plural not :controller. The documentation needs to be fixed then, eh?

02/08/08 18:02:51 changed by kampers

  • keywords set to docs.
  • component changed from ActiveSupport to ActionPack.
  • severity changed from major to normal.
  • summary changed from Bug: Rails 2.0 RC2 singleton resources ignore :plural option to [PATCH] map.resource docs incorrectly mention :plural option.

You're right. Here are patches to take care of that and do some other minor cleanup for trunk and 2-0-stable. Take a look.

For what it's worth, the resource docs are pretty nasty in general. They could use a thorough cleanup. This will take care of the immediate problem, though.

02/08/08 18:03:30 changed by kampers

  • attachment resource_docs_no_plural_option.trunk.diff added.

02/08/08 18:03:42 changed by kampers

  • attachment resource_docs_no_plural_option.2-0-stable.diff added.