Forum: Ruby on Rails preselected dropdown select in form

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cdd7dfeca927834e8dad7a54684990ff?d=identicon&s=25 Pingala Pingala (pingala)
on 2007-04-18 19:50
(Received via mailing list)

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

steps belongs_to recipe
recipes belongs_to category

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|
[,] }) %></p>

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,] }) %></p>

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

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.

Cdd7dfeca927834e8dad7a54684990ff?d=identicon&s=25 Pingala Pingala (pingala)
on 2007-04-19 12:14
(Received via mailing list)
up up....
anybody can help?

This topic is locked and can not be replied to.