开发者

How to create nested froms to create values in two different table at once in rails 3

开发者 https://www.devze.com 2023-03-19 11:21 出处:网络
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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号