Using rails_best_practices gem in Rails 5

Steps

Step 1

In Gemfile development group, add the rails_best_practices gem:

group :development do
  gem 'sqlite3'
  gem 'quiet_assets'
  gem 'thin'
  gem 'rails_best_practices'
end

Step 2

rails_best_practices .

Step 3

Add index to an existing column.

class AddIndexToPayments < ActiveRecord::Migration
  def change
    add_index :payments, :customer_id
    add_index :payments, :product_id
  end
end

Tip: Do not follow the rails_best_practices suggestion that says : Remove unused variable for form_for(@article). The reason is that when you use form partial to render a blank form and the form to edit, we need to instantiate an empty form for creating new record and load the existing record for editing. So, eventhough the variable is not used Rails uses the fact whether it is in database or not to distinguish between new and edit.

What happens to the old data after creating an index on a foreign column in MySQL ? Anyone?


Related Articles


Create your own user feedback survey