Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your error is telling you that the object f.bike is of class nil. You would have been expecting it to be an instance of class Bike. Obviously you have a line item in your view that doesn't have a bike record attached to it. To take care of the error so your view will display just add a check for blank?</p> <pre><code>li&gt;&lt;%= f.bike.biketype unless f.bike.blank? || f.bike.biketype.blank? %&gt;&lt;/li&gt; </code></pre> <p>As to why you have a line item with no bike? Well that's an entirely different question and there is not enough info here to answer that.</p> <p><strong>UPDATE Based on comments below</strong> Your button_to looks a little wrong. Try</p> <pre><code>&lt;%= button_to "Rent this Bicycle!", {line_items_path(:bike_id =&gt; @bike)}, {:id =&gt; "rentthisbike"} %&gt; </code></pre> <p>Using the curly braces ensures that Rails knows the second param is a css style not a param to be passed into the controllers action To check if your bike id is getting into the controller then check the params that are actually getting into the controller action that add the bike to the line item. You will be able to find this in your development.log file, find the post request for the action and one of the first lines in that action will list all the params. If you see the bike_id in that list then either one of 2 possible situations is occurring. 1) You are not accessing the params hash properly to get the bike id from it or 2) You are not setting the bike ID on the line item before saving the record.</p> <p>You should be able to access the id using <code>params[:bike_id]</code> If you don't see the bike id then you need to look again at the button_to code to see why it's not passing the bike ID</p> <p><strong>End of update</strong></p> <p>Hope that helps</p>
 

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