I have a problem with my nested form Here is it:
<%= form_for :project, method: :patch do |f| %>
<%= f.fields_for :todos_attributes do |todo_form| %>
<p>
<%= todo_form.text_field :text, placeholder:"Task name..."%>
</p>
<p>
<%= todo_form.collection_select(:project_id, @projects, :id, :title) %>
</p>
<% end %>
<a href="javascript:undefined" class="hideDiv">Cancel</a>
<%= f.submit %>
<% end %>
Here is my ProjectsController code to update selected project:
def update
@project = Project.find(params[:id])
@project.update(todo_params)
redirect_to root_path
end
def todo_params
params.require(:project).permit(:id, todos_attributes: [:text, :project_id])
end
The problem is that I get an error in update method: "Couldn't find Project with 'id'=index" "index" as understand is default value. How can I set it to be equal to the value(:project_id) selected in collection_select
in the form? Thank you!
Aucun commentaire:
Enregistrer un commentaire