I have this code: <%= f.select :name, [@m.each do |n| [ n.first_name , n.first_name ] end], :class => ''gam'' %> and i want it to display each of the first_name records from the table that @m is associated with in a drop-down. When i test this code the only option in the drop down menu it #Player:0x3c88008> (Player is the name of the table that @m is associated with) i know from previous testing that everything works fine besides this code. Any ideas or help would be fantastic! -- 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 https://groups.google.com/groups/opt_out.
On Mon, Nov 19, 2012 at 2:56 PM, Robert Negronida <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> I have this code: > > <%= f.select :name, [@m.each do |n| > [ n.first_name , n.first_name ] > end], :class => ''gam'' %> >#each returns @m, so what you want is #map or collect. Try <%= f.select :name, @m.map { |n| [n.first_name, n.first_name] }, :class => ''gam'' %>> > and i want it to display each of the first_name records from the table > that @m is associated with in a drop-down. When i test this code the > only option in the drop down menu it #Player:0x3c88008> (Player is the > name of the table that @m is associated with) i know from previous > testing that everything works fine besides this code. > > > Any ideas or help would be fantastic! > > -- > 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 https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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 https://groups.google.com/groups/opt_out.
On Nov 19, 2012, at 2:28 AM, Jim Ruther Nill wrote:> > > > On Mon, Nov 19, 2012 at 2:56 PM, Robert Negronida <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > I have this code: > > <%= f.select :name, [@m.each do |n| > [ n.first_name , n.first_name ] > end], :class => ''gam'' %> > > #each returns @m, so what you want is #map or collect. Try > > <%= f.select :name, @m.map { |n| [n.first_name, n.first_name] }, :class => ''gam'' %> > > > and i want it to display each of the first_name records from the table > that @m is associated with in a drop-down. When i test this code the > only option in the drop down menu it #Player:0x3c88008> (Player is the > name of the table that @m is associated with) i know from previous > testing that everything works fine besides this code.There''s an optimization for this: collection_select f.collection_select( :name, @m, :first_name, :first_name, :class => ''gam'' ) Walter -- 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 https://groups.google.com/groups/opt_out.
On Mon, Nov 19, 2012 at 10:12 PM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org>wrote:> > On Nov 19, 2012, at 2:28 AM, Jim Ruther Nill wrote: > > > > > > > > > On Mon, Nov 19, 2012 at 2:56 PM, Robert Negronida <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > > I have this code: > > > > <%= f.select :name, [@m.each do |n| > > [ n.first_name , n.first_name ] > > end], :class => ''gam'' %> > > > > #each returns @m, so what you want is #map or collect. Try > > > > <%= f.select :name, @m.map { |n| [n.first_name, n.first_name] }, :class > => ''gam'' %> > > > > > > and i want it to display each of the first_name records from the table > > that @m is associated with in a drop-down. When i test this code the > > only option in the drop down menu it #Player:0x3c88008> (Player is the > > name of the table that @m is associated with) i know from previous > > testing that everything works fine besides this code. > > There''s an optimization for this: collection_select > > f.collection_select( :name, @m, :first_name, :first_name, :class => ''gam'' ) >You''re right Walter but make sure to add an empty hash before the html options for the options parameter f.collection_select :name, @m, :first_name, :first_name, {}, :class => ''gam''> > Walter > > -- > 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 https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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 https://groups.google.com/groups/opt_out.
Something like that? <%= f.select :city_id, @cities.map { |city| [city.name, city.id] } %> Am Montag, 19. November 2012 07:57:39 UTC+1 schrieb Ruby-Forum.com User:> > I have this code: > > <%= f.select :name, [@m.each do |n| > [ n.first_name , n.first_name ] > end], :class => ''gam'' %> > > and i want it to display each of the first_name records from the table > that @m is associated with in a drop-down. When i test this code the > only option in the drop down menu it #Player:0x3c88008> (Player is the > name of the table that @m is associated with) i know from previous > testing that everything works fine besides this code. > > > Any ideas or help would be fantastic! > > -- > 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/sqaT9EYgOJ8J. For more options, visit https://groups.google.com/groups/opt_out.