Preselected dropdown select in form

Hi,

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

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

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

up up…
anybody can help?

thanks