How to create nested froms to create values in two different table at once in rails 3
I was stuck with a different scenario like say for example i have model movies and the 开发者_如何学JAVAother 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.
<%= 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
I don’t think HTML allows nested forms, see for example this question.
精彩评论