Common Model mistakes on Rails


1.  Don’t use automatically generated methods

2. N+1 problems
3. Don’t use scopes
4. Don’t know the difference between “after_create” and “after_commit”

  • “after_create” might result in invalid data if the ID is used before the transaction is completed.
  • Using “Sidekiq” or any other background worker I could always use “after_commit” to ensure the integrity of my data.
5. Always use CRM

6.  Don’t know the difference between “dependent destroy” and “delete_all”
7.  Don’t set default fields in migrations
8.  Don’t set constraints in migrations
9.  Don’t write reverse migrations in migrations
If you are not able to roll back, so what’s point in migrations!?
https://jetruby.com/

Comments