Reputation: 1
I have threes models: countries, states and cities. Countries has_many states and states has_many cities. When I create a new city I want to have a drop-down menu to pick the Country and State. I am not sure how to get the Country model linked with cities.
So I have something like this on the form for creating a new city:
<%= f.collection_select(:country_id, Country.all, :id, :country_name)%>
In the city model I have:
def country_id
end
That allows me to get the page. But I cannot submit the form. If I submit the form I get
unknown attribute: country_id
Upvotes: 0
Views: 234
Reputation: 623
in your form
<%= f.collection_select :country_id, Country.all, :id, :country_name %>
In your model make sure u have
attr_accessible :country_id
hope this works. but again post the relationships
Upvotes: 1