Pretty nice write up. I never saw the find_each before. Will have to try that out 🙂
Many programmers face similar problems over and over. So, here I am going to list out the common mistakes that can be avoided in Ruby on Rails Development.
1. Database column Indexing
At the beginning of programming , mostly during writing migrations, we forget to add indexes , which may or may not have any effect in initial stages of application, but will have drastic delay in fetching records from the database as the table size increases.
2. ActiveRecord transaction for saving multiple object
Whenever saving multiple objects in a single request, always use ActiveRecord::Base::transaction method to support atomicity. So, if any record has not saved the entire transaction, will get rolled back and nothing will be saved into the database.
Always add indexes to the column being used for searching records.
ActiveRecord::Base.transaction do @tasks.each do |task| task.save! end end
3. Using delete_all instead of destroy_all
View original post 1,031 more words