Using rails_best_practices gem in Rails 5
In Gemfile development group, add the
group :development do gem 'sqlite3' gem 'quiet_assets' gem 'thin' gem 'rails_best_practices' end
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?
Ace the Technical Interview
- Easily find the gaps in your knowledge
- Get customized lessons based on where you are
- Take consistent action everyday
- Builtin accountability to keep you on track
- You will solve bigger problems over time
- Get the job of your dreams
Take the 30 Day Coding Skills Challenge
Gain confidence to attend the interview