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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
<%= select_tag(:child_id, option_groups_from_collection_for_select(@parent, :children, :name, :id, :name)) %> -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Since this you are using "form_for" you want to use "f.select" not "select_tag" like in my example. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.