The documentation states as an example: select("post", "person_id", Person.find_all.collect {|p| [ p.name, p.id ] }, { :include_blank => true }) could become: <select name="post[person_id]"> <option></option> <option value="1" selected="selected">David</option> <option value="2">Sam</option> <option value="3">Tobias</option> </select> I have the following code in a _form.rhtml file: <%= select("category", "prnt_id", Prnt.find_all.collect {|p| [p.name, p.id]}, { :selected => ''prnt_id'' == @category.prnt_id, :include_blank => false } ) %> The drop down is created with the correct content, but is does NOT select the currently set value. The value is set if I use any other type of input (ie text_field). Is there an error in the doc? If so, does anybody know how ''selected'' is set? TIA g
> > > I have the following code in a _form.rhtml file: > <%= select("category", "prnt_id", Prnt.find_all.collect {|p| [p.name, p.id > ]}, > { :selected => ''prnt_id'' == @category.prnt_id, :include_blank => false } ) > %> > > The drop down is created with the correct content, but is does NOT select > the > currently set value. The value is set if I use any other type of input > (ie > text_field). > > Is there an error in the doc? If so, does anybody know how ''selected'' is > set?Try it without the :selected option. I use this all over the palce and that is the only difference I see between yours and mine. Rails will call @ category.prnt_id for you in the select helper. Also just as an FYI, :include_blank => false is the default setting. <%= select("category", "prnt_id", Prnt.find_all.collect {|p| [p.name, p.id]} ) %> -- Mark Van Holstyn mvette13@gmail.com http://lotswholetime.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060406/f327d126/attachment.html
Gerard wrote:> I have the following code in a _form.rhtml file: > <%= select("category", "prnt_id", Prnt.find_all.collect {|p| [p.name, > p.id]}, > { :selected => ''prnt_id'' == @category.prnt_id, :include_blank => false } > ) %> >Hey Gerard,>From the api:By default, post.person_id is the selected option. Specify :selected => value to use a different selection or :selected => nil to leave all options unselected. Instead of :selected => value, you''ve got :selected => ''prnt_id'' == @category.prnt_id You should probably try this: { :selected => @category.prnt_id, :include_blank => false } Dan -- Posted via http://www.ruby-forum.com/.
Mark Van Holstyn <mvette13@...> writes:> I have the following code in a _form.rhtml file:< <%= select("category", "prnt_id",> Prnt.find_all.collect {|p| [p.name, p.id]},{ :selected => ''prnt_id'' == <at> > category.prnt_id, :include_blank => false } ) %>The drop down is created with > the correct content, but is does NOT select the > currently set value. The value is set if I use any other type of input > (ietext_field).Is there an error in the doc? If so, does anybody know how > ''selected'' is set? > > Try it without the :selected option. I use this all over the palce and that > is the only difference I see between yours and mine. Rails will call <at> > category.prnt_id for you in the select helper. Also just as an FYI, > :include_blank => false is the default setting. > > <%= select("category", "prnt_id", Prnt.find_all.collect {|p| [ > p.name, p.id]} ) %>-- MarkMark, I have tried it that way too, and the way Dan Perez suggested after you, but still no joy: <%= select("category", "prnt_id", Prnt.find_all.collect {|p| [p.name, p.id] }) { :include_blank => false } ) %> or <%= select("category", "prnt_id", Prnt.find_all.collect {|p| [p.name,p.id]}))%> or Dan''s. All do not seem to generate a selected= in the html code. I''m using Rails 1.1. How about you? g
I am also using rails 1.1. Check to make sure that @category.prnt_id is returning what you expect it should be returning. It may be returning nil, or a value which doesnt exist in the options for the select. mark -- Mark Van Holstyn mvette13@gmail.com http://lotswholetime.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060406/ecb8d1e6/attachment.html
Mark Van Holstyn wrote:> I am also using rails 1.1. Check to make sure that @category.prnt_id is > returning what you expect it should be returning. It may be returning > nil, > or a value which doesnt exist in the options for the select. > > markI''m having the same issue as Gerard, using Rails 1.1.6. I cannot get it to select an option by default (or by specifying value to select). Here''s my code: <%= select("thing", "category_id", Category.find_all.collect { |c| [c.name, c.id] }) %> Yes, @thing.category_id is what I''m expecting and it is a value in the options. Does this work at 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel wrote:> Mark Van Holstyn wrote: >> I am also using rails 1.1. Check to make sure that @category.prnt_id is >> returning what you expect it should be returning. It may be returning >> nil, >> or a value which doesnt exist in the options for the select. >> >> mark > > I''m having the same issue as Gerard, using Rails 1.1.6. I cannot get it > to select an option by default (or by specifying value to select). > Here''s my code: > > <%= select("thing", "category_id", Category.find_all.collect { |c| > [c.name, c.id] }) %> > > Yes, @thing.category_id is what I''m expecting and it is a value in the > options. > > Does this work at all?I think I found the problem, actually. It looks like @thing.category_id is being treated as a String while c.id is being treated as a Fixnum. Annoying. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---