Jhon
Jhon

Reputation: 111

how to generate month wise data report in rails 3

I Am new in rails, I have facing some problem regarding month wise data report. I have a user table and transaction table with has_many association. transaction table has column type(buy or sell), amount(amount_value), and created_at and updated_at column and user_id.

How i can generate a user's month wise transaction report from this.

Upvotes: 0

Views: 633

Answers (1)

Arijoon
Arijoon

Reputation: 2300

Considering in your controller you have

@user = User.find(params[:id])

meaning you are in the users show action you can get their transactions as follows:

@transactions = @user.transactions

That should return an array containing all the transactions if your naming is right.

EDIT I was under the impression that you are using ruby on rails which means no need to write a sql query! If I'm wrong and you just want the sql query then you can find an answer in the comments!

Upvotes: 1

Related Questions