I have a piece of code that is needed in 2 of my controllers, but not all of them. Where does this method belong? I have read about helpers, but those seem to be for view-related code. Someone proposed the lib-folder, but that seems 'too far away' from the controller logic, i don't need it in views or models. Has someone experience with that sort of problem?
相关问题
- Eager-loading association count with Arel (Rails 3
- How to dynamically load partial view Via jquery aj
- Rails simple model attributes not saved to databas
- jquery-ui progressbar not showing
- PDF attachment in email is called 'Noname'
相关文章
- “No explicit conversion of Symbol into String” for
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
- Forward request from servlet to jsp
- Rails: Twitter Bootstrap Buttons when visited get
- is there a “rails” way to redirect if mobile brows
- Got ActiveRecord::AssociationTypeMismatch on model
- superclass mismatch for class CommentsController (
There are three options, the easiest (though, the most unclean) is the application controller. The other two options are a shared parent controller
Usage depends on how related these controllers are.
The final solution is a module
This is where the shared code required is for a handful of ad-hoc controllers, or if you are already using the inheritance above and this code doesn't quite fit into this subset (thus attempting to emulate multiple inheritance).