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.
The idea:
The questions:
The truth is that you can put your modules anywhere. Personally, my main use for modules is to create namespaces for my Active Record models to help keep things organized. Those module definitions just end up in the same files as my Active Record models.
You should always extend your concerns module with the supplied concerns base from Rails. Pathing is usually app/models/concerns/file. rb for model concerns and app/controllers/file.
The Ruby class Class inherits from Module and adds things like instantiation, properties, etc – all things you would normally think a class would have. Because Module is literally an ancestor of Class , this means Modules can be treated like classes in some ways. As mentioned, you can find Module in the array Class.
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 :
The /lib directory, if the module does not particularly 'interact' or concern the app/ and you treat the module as an internal plug-in.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With