开发者

Can I change my map.resources line in routes.rb to change the model name in the URL?

At the moment, I have this line in routes.rb

map.resources :usernotes

so my paths are /usernotes/new etc

But I realis开发者_如何学编程e now I want them to be like /notes/new

Is there a way to change the line in routes.rb to do this?


Yep, it's super-easy:

map.resources :usernotes, :as => 'notes'

See section 3.7.4 here:

http://guides.rubyonrails.org/v2.3.8/routing.html#controller-namespaces-and-routing (for Rails 2.3.x)

or here for Rails 3: http://guides.rubyonrails.org/routing.html#naming-routes


This will give you /notes and /notes/new etc

resources :notes, :controller=>"UserNotes"

You'll use new_note_path etc

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜