simple form - Rails - toggle boolean on click of a link -
i'm trying make app rails 4 , simple form.
i have models separately called project, scope , finalise. finalise belongs scope. scope belongs project. project accepts nested attributes scope , finalise. scope accepts nested attributes finalise.
i have attribute in finalise table called :draft.
if user creates project , sets :draft true, display link, when clicked, change :draft false.
i have following link in view:
<%= link_to 'finalise draft', finalise_toggle_draft_path(@project.scope.finalise.id), method: :patch %>
i have following method in controller:
def toggle_draft @finalise = finalise.find(params[:finalise_id]) @finalise.draft = false @finalise.finalised = time.now @finalise.save redirect_to project_path(project.find(params[:project_id])) end
when try this, error says: couldn't find project without id
does know i've done wrong?
my routes finalise are:
finalise_toggle_draft patch /finalises/:finalise_id/toggle-draft(.:format) finalises#toggle_draft finalises /finalises(.:format) finalises#index post /finalises(.:format) finalises#create new_finalise /finalises/new(.:format) finalises#new edit_finalise /finalises/:id/edit(.:format) finalises#edit finalise /finalises/:id(.:format) finalises#show patch /finalises/:id(.:format) finalises#update put /finalises/:id(.:format) finalises#update delete /finalises/:id(.:format) finalises#destroy
Comments
Post a Comment