Ruby on Rails: where should I store modules?

前端 未结 1 1148
长情又很酷
长情又很酷 2020-12-25 13:17

I am new to Ruby on Rails and my questions are about the application design, based on Rails 3. There are many data on the internet on the creation of standard websites (such

相关标签:
1条回答
  • 2020-12-25 13:39

    As you might know, modules are generally used either as namespaces or as mixins.

    Where you place a module depends on how tightly coupled a module is with the app directory . A few patterns in storing modules :

    1. The /lib directory, if the module does not particularly 'interact' or concern the app/ and you treat the module as an internal plug-in.

    2. The app/models directory, would be an appropriate place if your module is central to your business logic. A popular use case here, is where you use a module as a mixin to DRY your models/controllers.

    3. 37 Signals introduced a pattern of treating them as 'concerns' and storing them in app/concerns.

    If your module uses a gem, you may need to require the gem in the module (sometimes a require is not at all necessary).

    Your 3rd question is not clear. Sorry about that. Not quite sure what you're trying to do.

    0 讨论(0)
提交回复
热议问题