Guys, I have a partial for a form here: <% form_remote_tag(:controller => "posts", :action => "create") do %> <%= label_tag(:title, "Title") %><br /> <%= text_area_tag(:title, nil) %><br /> <%= label_tag(:body, "Description") %><br /> <%= text_area_tag(:body, nil) %><br /> <%= submit_tag("Post") %> <% end %> So I want to have a drop down where people can select what kind of update this is before they post it, something like: general or Job etc. On an example code I found this; <p> <%= f.label :group_ids, "Group" %> <%= f.collection_select :group_ids, Group.all(:order => "name ASC"), :id, :name %> <p> Wich basically renders a drop down menu with all "Groups" Im my case I need to do something like this: <p> <%= f.label :update_type, "Post" %> <%= f.collection_select :update_type, Post.all(:order => "name ASC"), :id, :name %> <p> except, I dont have a local variable f on my partial on the first chuck of code above. so what is the syntax to change my last last piece of code to work with the partial above so I can effectively render a drop down that will let me select the update_type ? any help will be great. Oliver. -- 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.
collection_select is build around an object, that''s why in the example they use f.collection_select, but you are using helpers with tag sufix, you don''t need an object in order to use those kind of helpers, so.. maybe you should use select_tag: *select_tag*(name, option_tags = nil, options = {}) you pass it a option_tags collection, you can get it from: *options_for_select*(container, selected = nil) you pass it an array of options or a hash, and if you want an option to be selected as default... then you pass it also your example should look something like: *select_tag(''name'', options_for_select(*Post.all(:order => "name ASC").collect {|p| [p.name, p.id]} *))* 2010/8/27 oliver torres <senortowers-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> Guys, I have a partial for a form here: > > <% form_remote_tag(:controller => "posts", :action => "create") do %> > <%= label_tag(:title, "Title") %><br /> > <%= text_area_tag(:title, nil) %><br /> > <%= label_tag(:body, "Description") %><br /> > <%= text_area_tag(:body, nil) %><br /> > <%= submit_tag("Post") %> > <% end %> > > > So I want to have a drop down where people can select what kind of > update this is before they post it, > something like: general or Job etc. > On an example code I found this; > > <p> > <%= f.label :group_ids, "Group" %> > <%= f.collection_select :group_ids, Group.all(:order => "name > ASC"), :id, :name %> > <p> > > Wich basically renders a drop down menu with all "Groups" > Im my case I need to do something like this: > > <p> > <%= f.label :update_type, "Post" %> > <%= f.collection_select :update_type, Post.all(:order => "name > ASC"), :id, :name %> > <p> > > > except, I dont have a local variable f on my partial on the first > chuck of code above. > so what is the syntax to change my last last piece of code to work > with the partial above so I > can effectively render a drop down that will let me select the > update_type ? > > any help will be great. > Oliver. > > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
oliver torres wrote:> Guys, I have a partial for a form here:[...]> So I want to have a drop down where people can select what kind of > update this is before they post it, > something like: general or Job etc. > On an example code I found this; > > <p> > <%= f.label :group_ids, "Group" %> > <%= f.collection_select :group_ids, Group.all(:order => "name > ASC"), :id, :name %> > <p> > > Wich basically renders a drop down menu with all "Groups" > Im my case I need to do something like this: > > <p> > <%= f.label :update_type, "Post" %> > <%= f.collection_select :update_type, Post.all(:order => "name > ASC"), :id, :name %> > <p> > > > except, I dont have a local variable f on my partial on the first > chuck of code above.Right, because form*_tag doesn''t create a FormBuilder object.> so what is the syntax to change my last last piece of code to work > with the partial above so I > can effectively render a drop down that will let me select the > update_type ? >If you had read the docs for collection_select, you would have found that it takes one more argument when no FormBuilder is involved. If that syntax doesn''t work in your particular case, select_tag (and perhaps options_from_collection_for_select ) will. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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.