开发者

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

开发者 https://www.devze.com 2023-03-22 22:59 出处:网络
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\" ins

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 soluti开发者_开发知识库on.

Thanks


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

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


In Rails 2.x, you can do

resource :setting, :as => 'settings'

The generated URLs will use setting, though.

0

精彩评论

暂无评论...
验证码 换一张
取 消