0

現在、私には3つのモデルがあります。

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を割り当てに割り当てていないためだと思いますが、それをどこに/どのように配置するかがわかりません。

4

1 に答える 1

0

https://github.com/ryanb/nested_form をお試しください

于 2012-07-10T11:51:06.023 に答える