I have this code: <%= select ''stuff'', ''id'', Stuff.find_by_sql( "SELECT stuffs.value, stuffs.id from stuffs WHERE account_id = " + @account.id.to_s + " ORDER BY stuffs.value ASC" ).collect{ |a| [a.value, a.id] }, {:include_blank => true, :selected => @user.stuff_profile.to_s } %> The issue is is that the blank space is added but the value is not set as selected. I have this same code (only using a different table) and that code adds the blank space and selects the correct drop down item. When I view the html everything looks good - option has a value as the id and I am telling it to select using the id. As far as I can see this should work, but it doesn''t. Any ideas of what I am doing wrong. Thanks, -S -- 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 -~----------~----~----~----~------~----~------~--~---
On Mar 19, 2:56 pm, Shandy Nantz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have this code: > > <%= select ''stuff'', ''id'', Stuff.find_by_sql( "SELECT stuffs.value, > stuffs.id from stuffs WHERE account_id = " + @account.id.to_s + " ORDER > BY stuffs.value ASC" ).collect{ |a| [a.value, a.id] }, {:include_blank > => true, :selected => @user.stuff_profile.to_s } %>I''m not sure what stuff_profile is, but the fact that you''re converting it, whatever it is, to a string means that it''s guaranteed not to be equal to any of those ids. Fred> The issue is is that the blank space is added but the value is not set > as selected. I have this same code (only using a different table) and > that code adds the blank space and selects the correct drop down item. > When I view the html everything looks good - option has a value as the > id and I am telling it to select using the id. As far as I can see this > should work, but it doesn''t. Any ideas of what I am doing wrong. Thanks, > > -S > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> I''m not sure what stuff_profile is, but the fact that you''re > converting it, whatever it is, to a string means that it''s guaranteed > not to be equal to any of those ids. > > FredI added that as a last ditch effort to try and make it work but with no luck. even without it it still doesn''t work. -- 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 -~----------~----~----~----~------~----~------~--~---
Shandy Nantz wrote:> > I added that as a last ditch effort to try and make it work but with no > luck. even without it it still doesn''t work.The stuff_profile is just a field with an id in it would should match the value in the option - not well named, I know. -- 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 -~----------~----~----~----~------~----~------~--~---
On 19 Mar 2009, at 15:09, Shandy Nantz wrote:> > Frederick Cheung wrote: >> I''m not sure what stuff_profile is, but the fact that you''re >> converting it, whatever it is, to a string means that it''s guaranteed >> not to be equal to any of those ids. >> >> Fred > > I added that as a last ditch effort to try and make it work but with > no > luck. even without it it still doesn''t work.what is stuff_profile ? what ever you pass to :selected should be an integer that will be == to the id of one of the instances of Stuff you are returning Fred> > -- > 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 -~----------~----~----~----~------~----~------~--~---
I changed the find and still nada. Here is what I got now: <%= select( ''stuff'', ''id'', Stuff.find( :all, :conditions => [''account_id = ?'', @account.id.to_s], :order => ''value ASC'').collect{ |a| [a.value, a.id] }, { :include_blank => true, :selected => @user.stuff_profile }) %> @user.stuff_profile is an id and when I look at the html there is an option field with that id as it''s value, so it should find it and make it the selected option. I beginning to wonder if this is a bug in the helper? -- 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 -~----------~----~----~----~------~----~------~--~---
On Mar 19, 4:08 pm, Shandy Nantz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I changed the find and still nada. Here is what I got now: > > <%= select( ''stuff'', ''id'', Stuff.find( :all, :conditions => [''account_id > = ?'', @account.id.to_s], :order => ''value ASC'').collect{ |a| [a.value, > a.id] }, { :include_blank => true, :selected => @user.stuff_profile }) > %> > > @user.stuff_profile is an idIs it definitely an integer ? (ie "1" is != 1) Fred and when I look at the html there is an> option field with that id as it''s value, so it should find it and make > it the selected option. I beginning to wonder if this is a bug in the > helper? > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On Mar 19, 4:08�pm, Shandy Nantz <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt> > wrote: >> I changed the find and still nada. Here is what I got now: >> >> <%= select( ''stuff'', ''id'', Stuff.find( :all, :conditions => [''account_id >> = ?'', @account.id.to_s], :order => ''value ASC'').collect{ |a| [a.value, >> a.id] }, { :include_blank => true, :selected => @user.stuff_profile }) >> %> >> >> @user.stuff_profile is an id > > Is it definitely an integer ? (ie "1" is != 1) > > Fred > and when I look at the html there is anNope, you are correct, I''m an idiot. The field was a chcracter varying field and when I added a to_i method call it worked. Sorry Fred, I guess I did understand what you were getting at, in the future I''ll know better. Thanks for the help. -S -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---