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

Child name Child name Child name Child Name Child name

<%=
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.

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)

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs