I have this statement ids = athlete.leagues.select("league_id").map(&league_id) getting this error Subject: [] athlete_injuries#create (TypeError) "wrong argument type Fixnum (expected Proc)" Anyone know what is going on here? by the way not a girl :) gerbdla = gerber david los angeles long story. -- 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.
On 5 Dec 2011 22:48, "gerbdla" <gerbdla-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have this statement > ids = athlete.leagues.select("league_id").map(&league_id) >What is it that you''re trying to do with this statement? The closest i can guess is the following: ids = athlete.leagues.select{|league|league.id = league_id}.map(&:league_id) But that just gives an array of league_ids the same as the one you started with. -- 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.
Instead this worked. Not sure exactly why the other works and not select. athlete.leagues.collect(&:league_id) On Dec 5, 3:46 pm, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5 Dec 2011 22:48, "gerbdla" <gerb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I have this statement > > ids = athlete.leagues.select("league_id").map(&league_id) > > What is it that you''re trying to do with this statement? The closest i can > guess is the following: > > ids = athlete.leagues.select{|league|league.id = league_id}.map(&:league_id) > > But that just gives an array of league_ids the same as the one you started > with.-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 6 December 2011 02:36, gerbdla <gerbdla-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Instead this worked. Not sure exactly why the other works and not > select. > > athlete.leagues.collect(&:league_id)because ".select" returns only those elements that return true to an evaluation, while ".collect" returns the result of the block passed to every element. Have a look at the Enumerable and Array api pages. http://www.ruby-doc.org/core-1.9.3/Enumerable.html -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.