Rails: new_*something*_path 变量在哪里设置?

发布于 2024-10-01 09:27:43 字数 322 浏览 0 评论 0原文

我为“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柳絮泡泡 2024-10-08 09:27:43

这些方法是在定义路由时自动创建的,并且在 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

所谓喜欢 2024-10-08 09:27:43

更新您的routes.rb以包含以下内容:

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

这将为使用GET发送的操作创建一个新路由。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文