I’m a total newbie to rails, and want to stop making the same tedious reports in excel and create a marketing analytics dashboard.
I have a User model, with created_at, marketing_source, purchases, and revenue.
What I want to do in sql is
select marketing_source, weekofyear(created_at), count(id), sum(revenue)
from User
where weekofyear(created_at) between # and #
group by marketing_source, weekofyear(created_at)
and then print this as a table to my page.
I’m just not exactly sure where and how to do the transformation. Do I put this via
sql.execute
in the controller code? Should I create a rake task to make a csv and then use javascript to read the csv and print out the table?
Any direction would be extremely appreciated.
Welcome to rails
If you are new to rails check out railscasts.com and http://guides.rubyonrails.org/
In rails you don’t have to write sql statements like this.
I am assuming you have done the database migrations and have all the necessary columns in you database
in your users_controller, I think this would do what you want.
Then in your corresponding view
/views/users/index.html.erb