On 13 June 2010 15:25, Adam Akhtar <[email protected]> wrote:
> How do i achieve what I want, namely to be able to access all the
> corrections for a given user
Create a method on User called "corrections" and collect up the user's
sentences' corrections.
class User < ActiveRecord::Base
has_many :sentences
def corrections
sentences.inject([]) { |memo, sentence| memo <<
sentence.corrections }.flatten.compact
end
end
http://ruby-doc.org/core/classes/Enumerable.html#M003140
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.