Older question, but I thought I'd throw in another option that I believe fits in with Rails conventions a little neater. The Likeable
namespace is responsible for dealing with any items that are likeable, and there are controllers that need to deal with building responses for likeable resources, and models for those likeable resources. Both of these can implement aspects of the Likeable
concept. What is needed is a breakdown within that namespace of the different responsibilities.
What I would do in this case is create a file in app/controllers/concerns/likeable/respondable.rb
that implements the Likeable::Respondable
functionality that a Controller provides. (You may find a better name than Respondable
for your needs - for instance, if the controller concern only really handles some logic around params, you may call it Likeable::Paramable
, etc.)
Similarly, if the model side of your Likeable
scaffold has to do mainly with persistence logic, you might define a Likeable::Persistable
module in app/models/concerns/likeable/persistable.rb
.
In this way, you can still keep all your logic for likeables in a single namespace, and get more specific for your controller and model concerns.
What's nice about this approach is that you can easily add to the namespace later if you find a need for, say, a utility module or class that needs to live in the lib
directory for dealing with special calculations or other shared functionality. In that case, you could easily define a Likeable::Utils
module in lib/likeable/utils.rb
, or something similar depending on the need, and everything will live under that one, consistent namespace.