开发者

Collection_select

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 hav开发者_如何学Pythone:

 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜