Topic: SUM column in events table & display result in rows of users table

Hello, my second day with the new Rails 4!

I have a events table which looks like this....

site_id  |  No_Events  |  Created_at
-------------------------------------------
0003    |       20         |   xxxx-xx-xx
0024    |       16         |   xxxx-xx-xx
0003    |       10         |   xxxx-xx-xx
0024    |       4           |   xxxx-xx-xx

And i have a sites table which i want to include the SUM of the 'No_Events' from the events table.

Basically i want to perform a sum over a month so from the 1st of month to last day of month.

and have the result shown in the sites table like this...

site_id  |  site_name  |  total_events  |    month
--------------------------------------------------------------
0003    |    Lincoln     |        30           |  July 2013
0024    |   Chester     |        20           |  July 2013

Can somebody please kindly show me the code required in my users controller and users view etc.?

Thank you

Last edited by pipy71 (2013-07-27 15:12:51)