Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

rails singular resource still plural?

I have a search route which I would like to make singular but when I specify a singular route it still makes plural controller routes, is this how it's supposed to be?

resource :search

Gives me

 search POST        /search(.:format)        {:action=>"create", :controller=>"searches"}
 new_search  GET    /search/new(.:format)    {:action=>"new", :controller=>"searches"}
 edit_search GET    /search/edit(.:format)   {:action=>"edit", :controller=>"searches"}
             GET    /search(.:format)        {:action=>"show", :controller=>"searches"}
             PUT    /search(.:format)        {:action=>"update", :controller=>"searches"}
             DELETE /search(.:format)        {:action=>"destroy", :controller=>"searches"}

Plural controller "searches"

I only have one route really... to create a search:

So I did: match "search" => "search#create"

I'm just wondering for the future if I'm still supposed to keep the controller plural? Rails 3.0.9

question from:https://stackoverflow.com/questions/6939688/rails-singular-resource-still-plural

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, that's how it's supposed to be. Quote from the Rails Guide on Routing:

Because you might want to use the same controller for a singular route (/account) and a plural route (/accounts/45), singular resources map to plural controllers.

http://edgeguides.rubyonrails.org/routing.html#singular-resources


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...