Ruby on Rails form_for 导致路径错误
在我的 Ruby on Rails 代码中,我有以下用于任务的 edit.html.erb 文件:
<%= render 'form' %>
然后,我在同一目录中有一个 _form 模板,其中包含以下代码:
<%= form_for @task do |f| %>
<%= fl.label :title %><br />
<% end %>
问题是,在尝试导航到编辑页面。该错误显示“未定义的任务路径”,因此据我所知,Rails 没有正确识别我的任务的路径。
程序的结构方式是我有一个包含许多任务的列表,每个任务都有一个列表。路由文件以这种方式声明结构:
resources :lists do
resources :tasks
end
如何让 form_for 识别我正在尝试编辑 /lists/:list_id/tasks/:task_id/edit 处的任务?
感谢您的帮助!
In my Ruby on Rails code, I have the following edit.html.erb file for tasks:
<%= render 'form' %>
I then have a _form template in the same directory with the following code:
<%= form_for @task do |f| %>
<%= fl.label :title %><br />
<% end %>
The problem is that I am getting an error when trying to navigate to the edit page. The error says "undefined task_path", so from what I can tell Rails is not properly identifying the path to my task.
The way the program is structured is that I have a List with many tasks, and each task has a list. The routes file declares the structure in this way:
resources :lists do
resources :tasks
end
How do I get the form_for to identify that I am trying to edit a task at /lists/:list_id/tasks/:task_id/edit?
Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用嵌套资源,在表单中使用它的正确方法是指定父母。
You are using Nested Resources the proper way to use that in a form is specifying the parent.