Home>

In both the index.html.erb file and the new.html.erb file,
I'm writing code that calls the create action and saves it to the database.
Both have the same code.

However, the name attribute when sending has changed, and only one of them can be saved.
Is there a mechanism to save both?
Thank you.

Code of form_with (same description for both index and new)
<% = form_with model: @enneagram_type, local: true do | form |%>
 <% = form.collection_select (: type_result_id, TypeResult.all,: id,: name, {}, {class: ": type_select"})%>
 <% = form.submit "register", class: "registerbtn"%>
<% end%>
When described in index.html.erb

The verification tool has the following name attribute.

name = "type_result_id"


Thanks for your professor.

  • Answer # 1

    indexIn the action@enneagram_typeDo you define?

    form_withControls the name etc. by looking at the passed model, so@enneagram_typeWithout definingnilIf left unchecked, it will not work as intended.