2012-07-10 60 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