Tutorial by Examples

To help to maintain clean code, Rails follows the principle of DRY. It involves whenever possible, re-using as much code as possible rather than duplicating similar code in multiple places (for example, using partials). This reduces errors, keeps your code clean and enforces the principle of writin...
In Rails, you find yourself looking at controllers, views, and models for your database. To reduce the need for heavy configuration, Rails implements rules to ease up working with the application. You may define your own rules but for the beginning (and for later on) it's a good idea to stick to co...
“Fat Model, Skinny Controller” refers to how the M and C parts of MVC ideally work together. Namely, any non-response-related logic should go in the model, ideally in a nice, testable method. Meanwhile, the “skinny” controller is simply a nice interface between the view and model. In practice, this...
ActiveRecord includes default_scope, to automatically scope a model by default. class Post default_scope ->{ where(published: true).order(created_at: :desc) } end The above code will serve posts which are already published when you perform any query on the model. Post.all # will only lis...
If you can say “YAGNI” (You ain’t gonna need it) about a feature, you better not implement it. There can be a lot of development time saved through focussing onto simplicity. Implementing such features anyway can lead to problems: Problems Overengineering If a product is more complicated than it...
"Fat Model, Skinny Controller" is a very good first step, but it doesn't scale well once your codebase starts to grow. Let's think on the Single Responsibility of models. What is the single responsibility of models? Is it to hold business logic? Is it to hold non-response-related logic? ...

Page 1 of 1