# One to many default values

**URL:** <https://www.ruby-forum.com/t/one-to-many-default-values/129970>\
**Category:** Rails\
**Created:** [February 23, 2008, 8:25am UTC](https://www.ruby-forum.com/t/one-to-many-default-values/129970 "2008-02-23T08:25:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![beexk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@beexk](https://www.ruby-forum.com/u/beexk)\
**Post date:** [February 23, 2008, 8:25am UTC](https://www.ruby-forum.com/t/one-to-many-default-values/129970/1 "2008-02-23T08:25:33Z")

</div>

Hi.  
I have two tables: users and pens.  
the relationship of user and pen is one to many.  
In controller, the return value is @pens(all pens belong to a specific  
user), but in view, i want to show out all pens’ value as default in  
 form, how to handle it?

Thank you!

---

<div class="post-metadata">

**Author:** ![beexk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@beexk](https://www.ruby-forum.com/u/beexk)\
**Post date:** [February 23, 2008, 8:36pm UTC](https://www.ruby-forum.com/t/one-to-many-default-values/129970/2 "2008-02-23T20:36:57Z")

</div>

Shih T. wrote:

> Hi.  
> I have two tables: users and pens.  
> the relationship of user and pen is one to many.  
> In controller, the return value is @pens(all pens belong to a specific  
> user), but in view, i want to show out all pens’ value as default in  
> form, how to handle it?
> 
> Thank you!

look at options\_for\_select() and options\_from\_collection\_for\_select(),  
both of which take a conditional select argument that automatically  
“selects” the current value the model has.

hth

ilan
