Reputation: 2409
I've build a management panel for a website I'm working on and it all works brilliant. Now there needs to be a front page that acts as a 'Dashboard.' It'll display different graphs representing various models and parts of the application over time. It'll also show smaller lists of various items (customers that need to be called etc.) I've got a dashboard working, but I'm just wondering if there's a better way of doing it in rails. I basically just have a dashboard controller:
class DashboardController < ApplicationController
def show
@statistics = {}
@statistics[:leads] = Lead.this_month.count
@statistics[:leads_by_day] = Lead.date_count
@statistics[:called_this_month] = Customer.called_this_month.count
end
end
I don't want to use any gems, because this is going to require a tonne of configuration and it needs to look a certain way
Upvotes: 2
Views: 711
Reputation: 4927
This can lead to a lot of code and conditions in the view layer and it might be hard to test.
Extract all code
You should extract all code to one or more classes. The advantages is that you can get really clean code with many one liner methods and you can test them in isolation from rails witch makes you test lightning fast. Fast Rails Tests by Corey Haines
There are different opinions for how to do this.
Make presenters
There is a great railscast about it ( it requires pro subscription )
Upvotes: 2