Forum: Ruby on Rails Problem with foreign key

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
566f436924664096e0b85dd885cf8fe6?d=identicon&s=25 Ali Fakheri (aliov85)
on 2008-12-02 14:30
Hello

I've a "User" model. A user, belongs to a state model.

I've the following in the user form:

[code]
    <%= f.select(:state_id, State.find(:all).map {|c| [c.name,
c.id]},{:prompt => "Select a canton"}, {:onchange =>
"#{remote_function(:url  => {:action => "update_municipals"},
                                                       :with =>
"'name='+value")}"}) %>
[/code]

However when I add a user, it's "state_id" is null, but if rename
state_id to "state", the id number of the state is saved correctly.

Thanks
This topic is locked and can not be replied to.