Rails: update nested resource from the view -
i need form update tasks, belong projects projects view , error
no route matches [patch] "/projects/1/tasks/1/edit"
this list of routes available
project_tasks_path /projects/:project_id/tasks(.:format) tasks#index post /projects/:project_id/tasks(.:format) tasks#create new_project_task_path /projects/:project_id/tasks/new(.:format) tasks#new edit_project_task_path /projects/:project_id/tasks/:id/edit(.:format) tasks#edit project_task_path /projects/:project_id/tasks/:id(.:format) tasks#show patch /projects/:project_id/tasks/:id(.:format) tasks#update put /projects/:project_id/tasks/:id(.:format) tasks#update delete /projects/:project_id/tasks/:id(.:format) tasks#destroy projects_path /projects(.:format) projects#index post /projects(.:format) projects#create new_project_path /projects/new(.:format) projects#new edit_project_path /projects/:id/edit(.:format) projects#edit project_path /projects/:id(.:format) projects#show patch /projects/:id(.:format) projects#update put /projects/:id(.:format) projects#update delete /projects/:id(.:format) projects#destroy projects_update_path post /projects/update(.:format) projects#update projects_add_path post /projects/add(.:format) projects#add post /projects/:project_id/tasks/:id/edit(.:format) tasks#edit root_path / projects#index
here's view code
<% @projects.each |project| %> <%= project.name %> <% project.tasks.each |task| %> <%= task.name %></p> <%= form_for [task.project, task], url: edit_project_task_path(task.project, task) |f| %> <%= f.label :name %> <%= f.text_field :name %> <%= f.submit "update task" %> <% end %> <% end %> <% end %>
you're trying submit request edit
route.
instead, try using project_task_path(task.project, task)
in form_for
. rails know send patch request proper route.
Comments
Post a Comment