dangerousdave
dangerousdave

Reputation: 6408

Handle Ruby on Rails resource when the singular is also plural?

Whats the best way to handle a singular resource, that itself is plural.

For example a "settings page", that displays a selection of different settings. As I am displaying a single "Settings" instance, I would expect to use the show action, but would want to have "settings" not "setting" in the url.

If I called the resource "settings_group" it would solve the problem, but that name is far from catchy, and not an ideal solution.

Thanks

Upvotes: 2

Views: 427

Answers (2)

asymmetric
asymmetric

Reputation: 3890

In Rails 2.x, you can do

resource :setting, :as => 'settings'

The generated URLs will use setting, though.

Upvotes: 0

apneadiving
apneadiving

Reputation: 115531

A quick way to achieve this is to write it yourself:

resources :settings, :except => :show
match "settings/:id" => "settings#show", :as => :setting

Upvotes: 1

Related Questions