2012-07-10 50 views
0

目前我有三个型号:Rails的嵌套表格范本

Songs have many Setlists through Allocations 
Setlists have many Songs through Allocations 
Allocations belong to Setlists and belong to Songs 

我此刻的形式如下:

<%=f.label :date, "Set a date" %> 
<%=f.date_select :date%> 

<div> 
    <%= render 'song' %> 
</div> 

<%=f.submit "Create Setlist", class: "btn btn-large btn-primary" %> 

上面给出的歌曲部分是:

<div id="songSelection"> 
<table class= "table table-striped table-bordered"> 
     <thead> 
      <th>Title</th> 
      <th>Artist</th> 
      <th>Add to Set</th> 
     </thead> 
      <tbody> 
     <% @songs.each do |song| %> 
     <tr> 
      <%= nested_form_for(@setlist.allocations.build(song_id: song.id)) do |builder| %> 
      <td><%= song.title %></td> 
      <td><%= song.artist %></td> 
      <td> 
       <%= builder.submit "Add Song", class: "btn btn-small btn-primary" %> 
      <% end %> 
      </td> 
     </tr> 
     <% end %> 
    </tbody> 
</table> 
</div> 

基本上我是tryi通过分配将歌曲分配给设定列表。目前它声明部分歌曲中的f没有被定义。如果我摆脱它,那么页面呈现正常,但无法正常工作(即,无论何时单击按钮添加重定向的歌曲,它都会保存对setlist日期的更改,但不会指定任何新的分配)。任何帮助将非常感激。我意识到我可能错过了信息,因为我对此有点新,所以如果需要任何额外的细节,请询问。

我试过使用由瑞安贝茨嵌套窗体宝石,但我无法得到它的工作。我想这是因为当它试图构建它,但不知道在哪里/我怎么会把那个英寸

回答

0
+0

我试着用这一点,但它不是分配歌曲ID的分配我仍然有问题...这是我的代码: \t' \t \t <%@ songs.each do | song | %> <%= nested_form_for(@ setlist.allocations.build(song_id:song.id))do | builder | %> ​​<%= song.title%> ​​<%= song.artist%> ​​<%= song.key%> ​​ \t <%= builder.submit “添加歌”,类: “BTN BTN小BTN-初级” %> \t <% end %> <% end %> \t' – TangoKilo 2012-07-10 12:27:30

+0

糟糕未在格式化二!将在实际问题中发布 – TangoKilo 2012-07-10 12:27:58