one to many default values

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 <select> form, how to handle it?

Thank you!

Shih Tony 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 <select> 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