ruby on rails - missing required keys: [:id] when updating a nested element -
first of lot helping me out.
i working on project tool, have project model has_many project_tasks. project_tasks belongs project.
i trying make mark complete action project tasks, can't seem project_task id in patch action.
here routes: (note have complete action project too, working fine)
resources :projects resources :project_tasks member patch :complete end end member patch :complete end end
rake routes
complete_project_project_task patch /projects/:project_id/project_tasks/:id/complete(.:format) project_tasks#complete project_project_tasks /projects/:project_id/project_tasks(.:format) project_tasks#index post /projects/:project_id/project_tasks(.:format) project_tasks#create new_project_project_task /projects/:project_id/project_tasks/new(.:format) project_tasks#new edit_project_project_task /projects/:project_id/project_tasks/:id/edit(.:format) project_tasks#edit project_project_task /projects/:project_id/project_tasks/:id(.:format) project_tasks#show patch /projects/:project_id/project_tasks/:id(.:format) project_tasks#update put /projects/:project_id/project_tasks/:id(.:format) project_tasks#update delete /projects/:project_id/project_tasks/:id(.:format) project_tasks#destroy complete_project patch /projects/:id/complete(.:format) projects#complete projects /projects(.:format) projects#index post /projects(.:format) projects#create new_project /projects/new(.:format) projects#new edit_project /projects/:id/edit(.:format) projects#edit project /projects/:id(.:format) projects#show patch /projects/:id(.:format) projects#update put /projects/:id(.:format) projects#update delete /projects/:id(.:format) projects#destroy
the view:
<%= link_to '', complete_project_project_task_path(@project, project_task.id), class: "glyphicon glyphicon-ok", id: "complete-#{project_task.id}", method: :patch %>
and controller action:
def complete @project = project.find(params[:project_id]) @project_task = project.project_task.find(params[:id]) if @project_task.completed_at.blank? @project_task.update_attribute(:completed_at, time.now) flash[:success] = 'task completed!' redirect_to root_path else @project_task.update_attribute(:completed_at, '') flash[:info] = 'task updated!' redirect_to root_path end end
the error getting : no route matches {:action=>"complete", :controller=>"project_tasks", :id=>nil, :project_id=>"26"} missing required keys: [:id]
in link_to add 2 arguments, @project (to project id) , project_task.id. seems getting project id correct, not project_task.id. tried change controller action @project_task = projecttask.find(params[:id]) without luck. (i tried few things out different arguments in link_to) not sure how retrieve that, hope 1 of can point me in right direction.
thanks in advance!
it looks project_task
variable in view not correctly set up. code should this:
<% @project.project_tasks.each |project_task| %> <%= link_to '', complete_project_project_task_path(@project, project_task.id), class: "glyphicon glyphicon-ok", id: "complete-#{project_task.id}", method: :patch %> <% end %>
(this considers project
model has_many :project_tasks
).
if setting correctly, can provide complete view , controller action?
Comments
Post a Comment