0

出力が 3 曲であることは (コンソールで確認して) わかっていますが、何らかの理由ですべてのページに 4 番目の曲が追加され続けています。曲は毎回異なり、なぜこれが起こっているのか、私は困惑しています. どんな助けでも大歓迎です!

私のコントローラーで

  def edit
    @songs = Song.all(order: 'title')
    @song = Song.find(params[:id])
    @setlist = Setlist.find(params[:id])
    @allocations = @setlist.allocations
  end

要求された完全なビュー コード:

まず、実際の編集ページのビュー:

<h1>Edit a Setlist</h1>
<div class="row">
   <div class="span8">
      <%=form_for(@setlist) do|f|%>

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

         <%=f.label :morning, "Morning" %>
         <%=f.radio_button :morning, true %>
         <%=f.label :morning, "Evening" %>
         <%=f.radio_button :morning, false %>

         <h2>Library</h2>   

        <div>
          <%= render 'library' %>
          <%= render 'currentSet' %> 
        </div>

         <%=f.submit "Save Setlist", class: "btn btn-large btn-primary" %>
      <% end %>
   </div>
</div>

現在のセットのパーシャル (ライブラリのパーシャルは無視します。これはネストされたフォームであり、まだ何も追加されていません):

<div id="currentSet">
   <h2>Current Setlist</h2>
     <table class= "table table-striped table-bordered">
       <thead>
         <th>Title</th>
         <th>Artist</th>
         <th>Root Key</th>
         <th>Remove</th>
       </thead>
       <tbody>
         <% if(@allocations.empty?) %>
            <tr><td>NO SONGS</td></tr>
         <% else %>
            <%= render @allocations %>
         <%end%>    
      </tbody>
     </table>
   </div>

そして割り当て:

<tr>
    <td><%= allocation.song.title %></td>
    <td><%= allocation.song.artist %></td>
    <td><%= allocation.song.key %></td>
    <td><%= link_to "Remove Song", allocation, method: :delete %></td>
</tr>

これが関連しているかどうかはわかりませんが、実際にレンダリングされた html も調査のために追加しました。

<tr>
    <td>S</td>
    <td>A</td>
    <td>K</td>
    <td><a href="/allocations/7" data-method="delete" rel="nofollow">Remove Song</a>...
</tr><tr>
    <td>S</td>
    <td>A</td>
    <td>K</td>
    <td><a href="/allocations" data-method="delete" rel="nofollow">Remove Song</a></td>
</tr>

私が奇妙なことに気付いたのは、最後のエントリが他のすべてのエントリとは異なり、URL に割り当て ID がないことです。

4

1 に答える 1

3

これを閉じるだけです:

  def edit
    @songs = Song.all(order: 'title')
    @song = Song.find(params[:id])
    @setlist = Setlist.find(params[:id])
    @allocations = @setlist.allocations
  end

ソングおよびセットリスト ファインダーで適切な :id を使用します (つまり、同じものではありません)。

于 2012-07-11T19:57:25.203 に答える