# How do you reconcile foreign keys for forms?

**URL:** <https://www.ruby-forum.com/t/how-do-you-reconcile-foreign-keys-for-forms/140329>\
**Category:** Rails\
**Created:** [June 13, 2008, 12:41am UTC](https://www.ruby-forum.com/t/how-do-you-reconcile-foreign-keys-for-forms/140329 "2008-06-13T00:41:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dezrtdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@dezrtdude](https://www.ruby-forum.com/u/dezrtdude)\
**Post date:** [June 13, 2008, 12:41am UTC](https://www.ruby-forum.com/t/how-do-you-reconcile-foreign-keys-for-forms/140329/1 "2008-06-13T00:41:05Z")

</div>

Hi all,

I’m looking to resolve foreign keys for forms – similar to the way  
“streamlined” does it. Although the actual value stored in an object  
is the foreign key integer, I’d like the actual name of the item  
displayed.

I’m _sure_ it’s easy. Thoughts?

Regards.

---

<div class="post-metadata">

**Author:** ![dezrtdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f4b2a3/32.png) [@dezrtdude](https://www.ruby-forum.com/u/dezrtdude)\
**Post date:** [June 13, 2008, 10:19am UTC](https://www.ruby-forum.com/t/how-do-you-reconcile-foreign-keys-for-forms/140329/2 "2008-06-13T10:19:57Z")

</div>

So you have one object, say a user  
and another one that belongs to the user, say an address

then:  
User model:

has\_one :address

Address model

belongs\_to :user

then after finding the user  
@user = User.find(params[:id])

you can access the address with  
@user.address  
or single address fields  
@user.address.city

belongs\_to and has\_many have a lot of options.  
You can set a foreign\_key if you don’t use the default user\_id in the  
address table
