Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Nested Model Form
    primarykey
    data
    text
    <p>At the moment I have three models:</p> <pre><code>Songs have many Setlists through Allocations Setlists have many Songs through Allocations Allocations belong to Setlists and belong to Songs </code></pre> <p>My form at the moment looks like:</p> <pre><code> &lt;%=f.label :date, "Set a date" %&gt; &lt;%=f.date_select :date%&gt; &lt;div&gt; &lt;%= render 'song' %&gt; &lt;/div&gt; &lt;%=f.submit "Create Setlist", class: "btn btn-large btn-primary" %&gt; </code></pre> <p>the song partial given above is:</p> <pre><code>&lt;div id="songSelection"&gt; &lt;table class= "table table-striped table-bordered"&gt; &lt;thead&gt; &lt;th&gt;Title&lt;/th&gt; &lt;th&gt;Artist&lt;/th&gt; &lt;th&gt;Add to Set&lt;/th&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;% @songs.each do |song| %&gt; &lt;tr&gt; &lt;%= nested_form_for(@setlist.allocations.build(song_id: song.id)) do |builder| %&gt; &lt;td&gt;&lt;%= song.title %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= song.artist %&gt;&lt;/td&gt; &lt;td&gt; &lt;%= builder.submit "Add Song", class: "btn btn-small btn-primary" %&gt; &lt;% end %&gt; &lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>Basically I'm trying to assign songs to setlists through allocations. At the moment it states that the f in the songs partial isn't defined. If I get rid of it then the page renders fine but doesn't function properly (i.e. whenever I click the button to add a song it redirects it saves the changes to the setlist date but doesn't assign any new allocations). Any help would be much appreciated. I realize that I may have missed out information as I'm somewhat new to this so if any additional details are needed please ask.</p> <p>I've tried using the nested form gem by Ryan Bates but I couldn't get it working. I think it's because it's not assigning a song id to the allocation when it goes to try and build it but not sure where/how I'd put that in.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload