Ruby on Rails Monday, April 30, 2012

Rails 3.1.3

I have tables

User => has_many :contribution
Contribution => belongs_to :user

in user.rb, I would like to define a method to compute the total
contribution
(sum of field 'price:integer' )

def total_contribution
@contributions = Contribution.find_all_by_user(self)
total = 0
@contributions.each do |c|
if c.done
total += c.price
end
end
return total
end

"Contribution.find_all_by(self)" gives an error

undefined method `find_all_by' for

Is there any better way?

soichi

--
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@googlegroups.com.
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.

No comments:

Post a Comment