Rails Best Practices 5: Optimize Migration

Migrations, in my opinion, are one of the best things in Rails since these allow the creation and populating the database using ruby code without having to worry about which type of db run below. That said, even writing the migration is better to follow some best practices. 1. DB Index The first practice I strongly recommend is to define indices for the external keys and f...

Read more

Rails Best Practices 3: Increase Controller’s readability

[POST UPDATE ON 19/07/2010 - 15:45] Continuing our analysis of the Rails Best Practices today we’ll see two other tricks to make more readable method of the controller.1. Methods within modelSuppose we have the classic user registry defined in such a way that an admin user can enable or disable other users.The deactivate method inside user Controller may be defined as follows:123456789101112131415161718class UserController < ApplicationController def deactivate @use...

Read more