grouped_options_for_select

Hi

I have two ojects @Parent @Child that i want to nest together to create
a select list for form.

@Parent @Child where @Parent has_many:Childern and Child
belongs_to:parent

In the db I have a field within child table call parent_id

I am using a form_for(@Parent...

and am using

<optgroup label="Parent">
    <option value="1">Child name</option>
    <option value="2">Child name</option>
    <option value="3">Child name</option>
  </optgroup>
  <optgroup label="Parent2">
    <option value="1">Child Name</option>
    <option value="2">Child name</option>
  </optgroup>

<%=
grouped_options_for_select(@Parent,Child.find(params[:parent_id]),:id,:name)%>

any help would be greatfull

<%= select_tag(:child_id,
option_groups_from_collection_for_select(@parent, :children, :name, :id,
:name)) %>

Since this you are using "form_for" you want to use "f.select" not
"select_tag" like in my example.

Sharagoz -- wrote:

Since this you are using "form_for" you want to use "f.select" not
"select_tag" like in my example.

Thanks Sharagoz

I had tried
<% option_groups_from_collection_for_select(@parent, :childern, :name,
:id, :name) %>

But was getting a "undefined method `inject' for #<Parent:0xb6828c1c>"
error from that line of code.

Dave Lynch wrote:

Sharagoz -- wrote:

Since this you are using "form_for" you want to use "f.select" not
"select_tag" like in my example.

Thanks Sharagoz

I had tried
<% option_groups_from_collection_for_select(@parent, :childern, :name,
:id, :name) %>

But was getting a "undefined method `inject' for #<Parent:0xb6828c1c>"
error from that line of code.

@parents should be a collection, like from
Parent.find(:all)

I needed to add a @parents line to my parent controller.

Under new method

@parents = Parent.find(:all)