Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to place Rails code that is not a model, view, controller or helper?

I want to share code not related to views between several controllers in my Rails app. Where in the directory structure should I place it?

EDIT: the code in question if something all controllers use to determine how they render the model data

like image 648
Bruno Antunes Avatar asked Jul 24 '09 14:07

Bruno Antunes


2 Answers

If the code is something like modules with utility methods in these could be placed in the lib folder. Alternatively you could create a common superclass for some of your controllers if they share behaviour.

Please post an example of the kind of code you're thinking of.

like image 80
mikej Avatar answered Sep 17 '22 14:09

mikej


If it's "something all controllers use", I would place it in a base class used by all controllers. The "application_controller" comes to mind.

like image 34
Pete Avatar answered Sep 21 '22 14:09

Pete