Calculating Values

I'm looking to calculate the values with in lets say the "Restaurants" table. For example, the number of restaurants and any other values with that tables. Then I would want to create a view to see those values. Any thought on how I would go about that?

Posted almost 4 years ago by Marquese Davis
Posted almost 4 years ago by Alex Yang

One way is to approach this is to create migration(s) to add each of the calculated fields you need to your Restaurants table. Then edit the code in your 'create' action in your controller so that for each new Restaurant object, you 1) calculate the values and 2) add these values to the new columns in your table. Be sure to edit the 'update' action as well to update those values when the object is changed!

To see those values in your app, you can use a gem like the Active Admin gem (https://github.com/activeadmin/activeadmin), but I'd recommend just building what you need yourself. The process is the same as adding a new view page. You might find Bootstrap's 'table' section useful:
http://getbootstrap.com/css/#tables

Hope that helps!

1