I have 2 models \"Country\" and \"League\", Country has many Leagues and League belongs to Country. When adding a league, I have a listbox with countries and when the form i
I was getting this error:
Country (#xxx) expected, got String (#xxx) This was how I fixed it in Rails 3.0.x:
<%= f.collection_select :country_id, Country.all.collect, :id, :name %>
for others who met the same problem:
this error is caused when you have two fields in your form like:
video: 'some string'
video['url']: 'some url'
then rails will crash with the error: expected Hash (got String) for param
the solution is quite simple: change 'video' to something else. e.g.:
video_origin_url: 'some string'
video['url']: 'some url'
You need to send country_id (which is the primary key) instead of name 'England' in that request. The relationships are associated with the primary keys.
<%= f.select :country, Country.all.collect {|c| [ c.name, c.id ] } %>
I was getting this error:
Artist (#xxx) expected, got String (#xxx)
This was how I fixed it in Rails 3.0.x:
class OtherModel
belongs_to :artist
validates :artist, :presence => true
#...
end
<%= form_for_other.collection_select :artist_id,
Artist.all, :id, :name,
:prompt => true %>
So it worked when I set the method on the collection_select input to the foreign key instead of the model name
The League model should reference country by its id ( country_id ) and not the string.
You need to use :country_id instead of :country
<%= f.select :country_id, Country.all.collect {|c| [c.name, c.id]} %>