Note that there are some explanatory texts on larger screens.

plurals
  1. POnil is not a symbol for form_for
    text
    copied!<p>I'm writing a simple form for editing customer's attributes (with Rails 3.1 and Ruby 1.9.3). The controller code:</p> <pre><code>def edit cust_id = params[:cust_id] output_id = params[:output_id] @cust = CustOutput.find(:all, :conditions =&gt; {:cust_id =&gt; cust_id, :output_id =&gt; output_id }) logger.info(@cust[0].cust_id) end </code></pre> <p>In the view:</p> <pre><code>&lt;h2&gt; Editing customer &lt;%=@cust[0].cust_id %&gt; with output id &lt;%=@cust[0].output_id %&gt;&lt;/h2&gt; &lt;div&gt; &lt;%= form_for @cust[0] do |cust| %&gt; &lt;%= render "shared/error_messages", :target =&gt; @cust[0] %&gt; &lt;div id='id' class='outerDiv'&gt; &lt;%= cust.text_field :cust_id, :size =&gt; 20 %&gt; &lt;/div&gt; &lt;div id='email1' class='outerDiv'&gt; &lt;label for='email1'&gt;Email Part1&lt;/label&gt; &lt;%= cust.text_field :email_part1, :size =&gt; 20 %&gt; &lt;/div&gt; &lt;div id='email2' class='outerDiv'&gt; &lt;label for='email2'&gt;Email Part 2&lt;/label&gt; &lt;%= cust.text_field :email_part2, :size =&gt; 20 %&gt; &lt;/div&gt; &lt;div id='dt' class='outerDiv'&gt; &lt;label for='dt'&gt;Delivery Type&lt;/label&gt; &lt;%= cust.text_field :delivery_type, :size =&gt; 20 %&gt; &lt;/div&gt; &lt;%= cust.submit "Save" %&gt; &lt;span class="cancel"&gt;&lt;%= link_to "Cancel", :action=&gt;"load", :cust_name=&gt;"#{@cust[0].cust_id}" %&gt; &lt;% end %&gt; &lt;/div&gt; </code></pre> <p>The error message I got from opening edit page (http://localhost:3000/edit?cust_id=2&amp;output_id=6):</p> <pre><code>nil is not a symbol Extracted source (around line #3): 1: &lt;h2&gt; Editing customer &lt;%=@cust[0].cust_id %&gt; with output id &lt;%=@cust[0].output_id %&gt;&lt;/h2&gt; 2: &lt;div&gt; 3: &lt;%= form_for @cust[0] do |cust| %&gt; 4: &lt;%= render "shared/error_messages", :target =&gt; @cust[0] %&gt; 5: &lt;div id='id' class='outerDiv'&gt; 6: &lt;%= cust.text_field :cust_id, :size =&gt; 20 %&gt; </code></pre> <p>The first thing is to check whether @cust[0] passed in is a nil object. In rails console I checked (with the provided cust_id and output_id) </p> <pre><code>@cust = CustOutput.find(:all, :conditions =&gt; {:cust_id =&gt; 2, :output_id =&gt; 6 }) CustOutput Load (0.7ms) SELECT "cust_outputs".* FROM "cust_outputs" WHERE "cust_outputs"."cust_id" = 22 AND "cust_outputs"."output_id" = 6 =&gt; [#&lt;custOutput cust_id: 2, output_id: 6, email_part1: "abc@company.com", email_part2: nil, delivery_type: "ftp"&gt;] </code></pre> <p>Also from the logger I put in controller, there's actually a valid and correct cust_id output in the log. So, why do I still get nil is not a symbol error message? I've checked on CustOutput model as well and all attr_accessible fields are present.</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