0

I'm planning on making a table in my view that is a summary of the data I've collected in my database.

For example, what I want to do is count how many times '1' is the response for gender, and display that count. I've had trouble making counters in Ruby before, so I wanted to find out how I should do this before I shoot myself in the foot.

I can imagine there is a database function call that sums the the column - but do I perform this action in my view? Or is it something a bit more tricky related to the MVC.

Thank you for your time.

1
  • In terms of the MVC Part. Don't do the calculation in the view. Do the calculation in the model or a service class/object and then pass the result to your view. Commented Nov 24, 2014 at 23:54

1 Answer 1

1

How about ActiveRecord::Calculations ? For example Gender.calculate(:count, :all)

See: http://api.rubyonrails.org/classes/ActiveRecord/Calculations.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.