# Problem with foreign key

**URL:** <https://www.ruby-forum.com/t/problem-with-foreign-key/154636>\
**Category:** Rails\
**Created:** [December 2, 2008, 2:30pm UTC](https://www.ruby-forum.com/t/problem-with-foreign-key/154636 "2008-12-02T14:30:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashil\_2p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3d9bf3/32.png) [@ashil\_2p](https://www.ruby-forum.com/u/ashil_2p)\
**Post date:** [December 2, 2008, 2:30pm UTC](https://www.ruby-forum.com/t/problem-with-foreign-key/154636/1 "2008-12-02T14:30:54Z")

</div>

Hello

I’ve a “User” model. A user, belongs to a state model.

I’ve the following in the user form:

```auto
    <%= 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")}"}) %>
```

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
