# Preselected dropdown select in form

**URL:** <https://www.ruby-forum.com/t/preselected-dropdown-select-in-form/92372>\
**Category:** Rails\
**Created:** [April 18, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/preselected-dropdown-select-in-form/92372 "2007-04-18T19:50:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pingala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@pingala](https://www.ruby-forum.com/u/pingala)\
**Post date:** [April 18, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/preselected-dropdown-select-in-form/92372/1 "2007-04-18T19:50:45Z")

</div>

Hi,

quite new to rails and ruby… so still wondering how does it  
work… 😉

i have three tables structured as follow:

1. categories
2. recipes
3. steps

where  
steps belongs\_to recipe  
recipes belongs\_to category

and  
category has\_many recipes  
recipe has\_many steps

i’ve created the standard scaffold for the three above… everything  
went ok,  
i’ve modified the models for the constraints on the FKs, i’ve modified  
the views  
to add a select dropdown to show in the recipe edit/new form the  
categories, and  
in the step edit/new form the recipes.

in the \_form.rhtml for recipes i’ve:  
\<%= select(“recipe”, “category\_id”, Category.find(:all).collect {|c|  
[c.name, c.id] }) %\>

and in case of editing it shows the right category preselected.

in the \_form.rhtml for steps i’ve:  
\<%= select(“step”, “recipe\_id”, Recipe.find(:all).collect {|c|  
[c.title, c.id] }) %\>

in this case the preselection doesn’t work…

now to create a step inside a recipe i’ve a link in the main recipe  
edit/show page like that:  
\<%= link\_to “Create new Step”, {:controller =\> “step”, :action =\>  
“new”, :recipe\_id =\> @recipe} %\>

that create a link like this one (assuming i’m viewing the recipe  
id#2):  
[http://localhost:3000/step/new?recipe\_id=2](http://localhost:3000/step/new?recipe_id=2)

hope i’m clear enough… how all this can works? what i’m doing wrong?  
what’s the logic to follow?

thanks for any suggestion  
really appreciated.

KR,  
Pingala

---

<div class="post-metadata">

**Author:** ![pingala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@pingala](https://www.ruby-forum.com/u/pingala)\
**Post date:** [April 19, 2007, 12:14pm UTC](https://www.ruby-forum.com/t/preselected-dropdown-select-in-form/92372/2 "2007-04-19T12:14:51Z")

</div>

up up…  
anybody can help?

thanks
