簡體   English   中英

Rails嵌套模型表格

[英]Rails Nested Model Form

目前,我有三種模型:

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>

基本上,我正在嘗試通過分配將歌曲分配給設置列表。 目前,它指出歌曲部分中的f尚未定義。 如果我擺脫了它,則頁面可以正常顯示,但無法正常運行(即,每當我單擊按鈕添加歌曲時,頁面就會重定向,它將更改保存到設置列表日期,但不分配任何新分配)。 任何幫助將非常感激。 我意識到我可能已經錯過了信息,因為我對此有些陌生,因此如果需要任何其他詳細信息,請詢問。

我嘗試使用Ryan Bates的嵌套表格gem,但無法正常工作。 我認為這是因為在嘗試構建歌曲時並沒有為分配分配歌曲ID,但是不確定在哪里/如何放置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM