0

I was stuck with a different scenario like say for example i have model movies and the other is releases. I want to create a new form in the apps/views/movies/new.html.erb. In the new i wanna have the fields for movies table eventually ill be having a form for it and at the same time i want to add the movie release information to the other table releases.Like it will be nested form as follows

<%= form_for(@movies)......%>

<% files for movies table %>

2nd form <%=form_for :releases %>

   <% fields for releases table%>

so form one carries the data to movies table when user clicks on submit button. But i want to pass the the values to release table also with this click using a nested form. Is it possible to have nested forms. If so i wanted some help on how it can be achieved exactly. Help me out please.

2 Answers2

1
<%= form_for(@movies) do |f| %>
# fields for movie
  <%= f.fields_for :releases do |nested_f| %>
#fields for your nested form releases
  <% end %>
<% f.submit %>
<% end %> 

Also in Movie.rb model add this line. accepts_nested_attributes_for :releases More information there

Mikhail Nikalyukin
  • 11,867
  • 1
  • 46
  • 70
0

I don’t think HTML allows nested forms, see for example this question.

Community
  • 1
  • 1
Smar
  • 8,109
  • 3
  • 36
  • 48