[英]Ruby on Rails: where should I store modules?
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 as blogs) on Rails, but my application requires more than just "post and read" and I am not sure how to implement that. 我是Ruby on Rails的新手,我的问题是关于应用程序设计,基于Rails 3.在Rails上创建标准网站(如博客)的互联网上有很多数据,但我的应用程序需要的不仅仅是“发布和阅读“我不知道如何实现这一点。
The idea: 想法:
The questions: 问题:
As you might know, modules are generally used either as namespaces or as mixins. 您可能知道,模块通常用作命名空间或mixins。
Where you place a module depends on how tightly coupled a module is with the app directory . 放置模块的位置取决于模块与app目录的紧密耦合程度。 A few patterns in storing modules :
存储模块中的一些模式:
The /lib directory, if the module does not particularly 'interact' or concern the app/ and you treat the module as an internal plug-in. / lib目录,如果模块没有特别“交互”或关注应用程序/并且您将模块视为内部插件。
The app/models directory, would be an appropriate place if your module is central to your business logic. 如果您的模块是业务逻辑的核心,那么app / models目录将是一个合适的位置。 A popular use case here, is where you use a module as a mixin to DRY your models/controllers.
这里是一个流行的用例,您可以使用模块作为混合来干燥您的模型/控制器。
37 Signals introduced a pattern of treating them as 'concerns' and storing them in app/concerns. 37信号引入了一种将其视为“关注点”并将其存储在app / Concer中的模式。
If your module uses a gem, you may need to require the gem in the module (sometimes a require is not at all necessary). 如果您的模块使用gem,您可能需要在模块中需要gem(有时候根本不需要)。
Your 3rd question is not clear. 你的第3个问题不明确。 Sorry about that.
对于那个很抱歉。 Not quite sure what you're trying to do.
不太清楚你想要做什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.