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.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

Rails 3 forces singleton resource names to be a singular word

#4089

I want a resource named "preferences" in Rails 3, but current routing implementation forces singleton resource names to singular form regardless of if they were specified in plural. In this example:

resource :preferences

generates these helpers: admin_preference, new_admin_preference, edit_admin_preference (notice the singular form)

Accordingly, the URLs for this resource are in the "/preference/*" form.

For now, I'm using this workaround to fix the URLs:

resource :preferences, :as => :preferences

But the generated URL helpers stay in singular form.

In Rails 2.3.x it was possible to have a singleton route named with a plural word.

Reported by Mislav · March 2nd, 2010 @ 07:10 AM

State: resolved
Milestone: 3.0.2
Assigned to: josh josh
Importance: Low

Activity

  1. José Valim
    José Valim
    • Assigned user set to josh
    • Milestone cleared.

    March 3rd, 2010 @ 08:39 AM

  2. josh
    josh
    • State changed from new to wontfix

    Hmm, I'm split here.

    Enforcing the singular convention and requiring explicit overrides seems good in a way.

    resource :preference, :as => :preferences
    

    If you really want this, I'll accept a patch for it.

    March 6th, 2010 @ 07:08 PM

  3. Mislav
    Mislav

    I'm all for explicit overrides, but :as only lets me manually override the path segment. The url helpers still remain in singular form, and I want them in plural because that's how they were in the 2.3.x app.

    To me, preference_path just looks wrong. It's not a single preference. It's a page with multiple preferences. Still, there's no way of overriding what word form will be used for these helpers.

    March 10th, 2010 @ 03:27 AM

  4. Andrew White
    Andrew White
    • Tag changed from pluralize, rails3, resource, routing, singleton to patch, pluralize, rails3, resource, routing, singleton

    This is also a problem for me bringing sites forward as most of them have singleton resources named settings. Obviously it's a relatively easy fix to search and replace settings_path with setting_path in all the views but I'm in agreement with Mislav that it just looks wrong.

    I've attached a patch which restores the behaviour from 2.3 and adds a failing test.

    BTW, I had to update rack-mount to 0.6.1 to get all the tests to pass - maybe you want to bump the dependency in the gemspec.

    March 10th, 2010 @ 12:29 PM

  5. josh
    josh
    • State changed from wontfix to open

    March 10th, 2010 @ 02:10 PM

  6. Repository
    Repository
    • State changed from open to resolved

    March 15th, 2010 @ 02:46 PM

  7. Mislav
    Mislav

    Thanks for fixing this!

    March 15th, 2010 @ 02:52 PM

  8. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM