I would like to put some statistics right in front of my site, like:
# jobs/index.html.haml
.panel
.panel-heading
%h4 Statistics
.panel-body
.col-md-9.col-xs-9
%h5.pull-left Users
.col-md-3.col-xs-3
%h5.pull-right= @usercount
.col-md-9.col-xs-9
%h5.pull-left Companies
.col-md-3.col-xs-3
%h5.pull-right= @companycount
.col-md-9.col-xs-9
%h5.pull-left Categories
.col-md-3.col-xs-3
%h5.pull-right= @categorycount
.col-md-9.col-xs-9
%h5.pull-left Total offers gathered
.col-md-3.col-xs-3
%h5.pull-right= @jobcount
At the moment these variables are all set in controller:
# controller: jobs, action: index
@jobcount = Job.count
@usercount = User.count
@categorycount = Category.count
@companycount = Job.distinct.count('company')
but I believe that's the worst way to do this in MVC. Can anybody tell me how it should be done?
I would go with this style:
@statistics = {
job_count: Job.count,
user_count: User.count,
category_count: Category.count,
company_count: Job.distinct.count('company')
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With