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 is submitted, the actual country is send:
{"commit"=>"Create League",
"authenticity_token"=>"wuAuj5vowkk2R56TuFkWE8J3x3vue5RbnNPcbpjuG3Q=",
"utf8"=>"✓",
"league"=>{"league_short"=>"CL",
"country"=>"England",
"level"=>"2",
"league"=>"The Championship"}}
But then I get this error message:
Country expected, got String
In the Country model I have country_id (integer) and country (string) as fields, in the League model I have country as a string field. In the League controller I have this to pouplate the dropdown: @countries = Country.dropdown_list
. In the league/new view I have this select field: <%= f.select :country, @countries %>
. What is going wrong?
You need to use :country_id instead of :country
<%= f.select :country_id, Country.all.collect {|c| [c.name, c.id]} %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With