开发者

Rails: Where does new_*something*_path variable get set up?

I created a scaffold for 'messages', and new_message_path and edit_message_path (for use in link_to's) are all set up, but now I've created app/views/messages/sent.html.erb, and I want to do something along the lines of <%= link_to 'Sent', sent_message_path %>, but I can't figure out h开发者_开发技巧ow to do that. I get

undefined local variable or method `sent_message_path' for #<ActionView::Base:0x103117c50>


Those methods are created automatically when routes are defined and in the case of RESTful routes, they follow a predictable convention.

Running 'rake routes' is a helpful way of seeing all of the routes being generated.

I recommend you read: http://guides.rubyonrails.org/routing.html


Update your routes.rb to contain something along the lines of:

map.resources :messages, :collection => { :sent => :get }

This will create a new route for the sent action using GET.


Answer for your question is situated at http://railsapi.com/doc/rails-v2.3.8/classes/ActionController/Resources.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜