Snips
Snips

Reputation: 6773

Where to place general app methods?

I have a Rails app with the usual application_controller, and a controller (and model) for each of the tables. I also added a pages_controller, for the additional web pages my app uses, this is merely an empty method supporting the corresponding views.

Now I would like to add some methods and pages that provide some overall monthly stats for the app, pulling data from each of the tables, grouped by month.

Where does Rails convention say I should put these methods?

Thank you.

Upvotes: 0

Views: 98

Answers (2)

Dave Newton
Dave Newton

Reputation: 160321

I'm not sure there's enough info here to create meaningful answers.

If you want model-specific stats, a module/mixin might make sense. It would provide normalized access to model-specific data. Depending on what you actually need, each model could have specific stat presentation layers.

There are many ways to implement this, but the code itself would likely live in a namespaced lib directory (if you're asking specifically about physical location).

Upvotes: 1

Arthur Neves
Arthur Neves

Reputation: 12148

You could either add the stats logic to your model, if you have a separated model for stats. Or you can create some class to handle that for you, therefor this file should be in lib/.

Upvotes: 0

Related Questions