Would it be ok to put an "average price" calculation, as below, in the view?
Or is this against MVC and is it better to do this in the controller?
<p>Average price: <%= @seller.total_sales / @seller.num_sales %></p>
Would it be ok to put an "average price" calculation, as below, in the view?
Or is this against MVC and is it better to do this in the controller?
<p>Average price: <%= @seller.total_sales / @seller.num_sales %></p>
Neither. Put it in the model. Then it becomes easy to unit test.
Ask you several things:
Will this average price will be often displayed Is it a part of a view (is it used to display something ?) Does it need complex things to get/calcul/retrieve or whatever ?
If you think it's just an hint for your user, it's used only once, then you can let it in your view.
But if you feel unconfortable with it, or you need to do more complex maths on the price, put it your model..
Put your business logic where it belongs in the model:
<p>Average price: <%= @seller.get_average_price () %></p>