Rails: new_*something*_path 变量在哪里设置?
我为“messages”创建了一个脚手架,并且 new_message_path 和 edit_message_path (用于 link_to 中)都已设置完毕,但现在我已经创建了 app/views/messages/sent.html.erb,我想沿着<%= link_to 'Sent', sent_message_path %> 行,但我不知道该怎么做。我明白了
undefined local variable or method `sent_message_path' for #<ActionView::Base:0x103117c50>
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 how to do that. I get
undefined local variable or method `sent_message_path' for #<ActionView::Base:0x103117c50>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这些方法是在定义路由时自动创建的,并且在 RESTful 路由的情况下,它们遵循可预测的约定。
运行“rake paths”是查看生成的所有路由的有用方法。
我建议您阅读:http://guides.rubyonrails.org/routing.html
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
更新您的routes.rb以包含以下内容:
这将为使用GET发送的操作创建一个新路由。
Update your routes.rb to contain something along the lines of:
This will create a new route for the sent action using GET.
您的问题的答案位于 http://railsapi.com/ doc/rails-v2.3.8/classes/ActionController/Resources.html
Answer for your question is situated at http://railsapi.com/doc/rails-v2.3.8/classes/ActionController/Resources.html