Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3.2 - Nested Resource Passing ID
    text
    copied!<p>Okay so my associations are:</p> <pre><code>Outlet -&gt; has_many :monitorings Monitoring -&gt; belongs_to :outlet </code></pre> <p>My Routes:</p> <pre><code>resources :outlets do resources :monitorings end </code></pre> <p>View:</p> <pre><code>&lt;%= link_to new_outlet_monitoring_path(@outlet) %&gt; </code></pre> <p>When I click the link, the logs show that the outlet_id is passed as a parameter to the new page correctly. But when saving the monitoring record, the outlet_id becomes nil.</p> <p>Any help?</p> <p><strong>UPDATE:</strong></p> <pre><code># views/monitorings/_form.html.erb &lt;%= form_for(@monitoring) do |f| %&gt; &lt;h2&gt;Type of Monitoring&lt;/h2&gt; &lt;fieldset data-role="controlgroup" &gt; &lt;div class="radio-group"&gt; &lt;%= f.radio_button :mtype, "Full" %&gt;&lt;%= f.label :mtype, "Full", value: "Full" %&gt; &lt;%= f.radio_button :mtype, "Partial" %&gt;&lt;%= f.label :mtype, "Partial", value: "Partial" %&gt; &lt;%= f.radio_button :mtype, "None" %&gt;&lt;%= f.label :mtype, "None", value: "None" %&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;hr&gt; &lt;%= f.submit "Next Step" %&gt; &lt;% end %&gt; </code></pre> <p>And the controller:</p> <pre><code># controllers/monitoring_controller.rb def new @monitoring = Monitoring.new respond_to do |format| format.html # new.html.erb format.json { render json: @monitoring } end end def create @monitoring = Monitoring.new(params[:monitoring]) respond_to do |format| if @monitoring.save format.html { redirect_to @monitoring, notice: 'Monitoring was successfully created.' } format.json { render json: @monitoring, status: :created, location: @monitoring } else format.html { render action: "new" } format.json { render json: @monitoring.errors, status: :unprocessable_entity } end end end </code></pre>
 

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