Ruby on Rails Monday, April 30, 2012

On 30 April 2012 09:03, Soichi Ishida <lists@ruby-forum.com> wrote:
> Rails 3.1.3
>
> I have tables
>
> User  => has_many :contribution

That should be :contributions, plural.

> 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)

Just use
@contributions = self.contributions

Colin

--
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