Answer the question
In order to leave comments, you need to log in
How to display sum of column values from a table?
Hello.
Let's say we have the following scheme:
users (has_many posts)
posts(belongs_to users)
---pages (let's say)
We need to display in the statistics how many pages a particular user has in all his posts. How to implement?
Answer the question
In order to leave comments, you need to log in
pages это что? Если количество страниц для поста, то:Post.where(user_id: params[:user_id]).sum(:pages)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question