Note that there are some explanatory texts on larger screens.

plurals
  1. POcollection_select giving ActiveRecord::AssociationTypeMismatch
    text
    copied!<p>I'm not sure if I'm asking this question right or am just too tired for it to be obvious.</p> <p>My code is:</p> <p>_form.html.haml</p> <pre><code> = f.collection_select :category, Category.where(:user_id =&gt; current_user.id), :id, :name </code></pre> <p>What I get is </p> <pre><code> ActiveRecord::AssociationTypeMismatch in LinksController#create Category(#70203963939880) expected, got String(#70203929255820) </code></pre> <p>Log is</p> <pre><code> Started POST "/links" for 127.0.0.1 at 2012-11-12 22:14:05 -0800 Processing by LinksController#create as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"z4RYcUW3hGLfKBAwQLMZbye2I1mn16fg6BSBGe7GILU=", "link"=&gt;{"name"=&gt;"SFGate", "url"=&gt;"http://www.sfgate.com/", "category"=&gt;"1"}, "commit"=&gt;"Save"} Completed 500 Internal Server Error in 0ms </code></pre> <p>It appears as though its passing :id as a string instead of an integer. Any clues?</p> <p>Update:</p> <pre><code>class Category &lt; ActiveRecord::Base belongs_to :user has_many :links attr_accessible :name, :color, :position COLOR_CODES = ["Green", "Blue", "Yellow", "Orange", "Red", "Purple", "Pink"] end class Link &lt; ActiveRecord::Base belongs_to :user belongs_to :category attr_accessible :category, :name, :position, :url, :user_id end </code></pre> <p>Fixed: I had </p> <pre><code> t.integer :category </code></pre> <p>instead of </p> <pre><code> t.integer :category_id </code></pre> <p>switched everything over and its working perfect - I guess I was too tired :)</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