I have a rails controller and a resque worker. Both share a couple of functions. Where should I put these functions so that I can follow the DRY principle and Rails conventions?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To me, this sounds like a good case for a service layer. One of my coworkers wrote up a nice summary of the concept: http://blog.carbonfive.com/2012/01/10/does-my-rails-app-need-a-service-layer/
Service layers are a common feature in many other web app MVC frameworks and something many Rails applications choose to use when fat models do not provide an appropriate encapsulation of responsibilities in their problem domain.
Without knowing more I’m afraid I can’t offer a more specific answer. My next step would be to try to consider what this service should be named. Is it a factory that build something we have a name for? Do is fulfill a specific role we can name it after?