Friday, July 20, 2012

Speed up updates of large datasets/records in Rails

Suppose we have 10,0000 users. We can do the following

User.find_each |user|
  user.update_attributes(status: 'active')
But that takes a long to complete. Executing raw sql over ActiveRecord speeds things up tremendously.

User.connection.execute("update users set status = 'active'")

Monday, July 16, 2012

Get ruby constant from string


Rails generator to generate rspec files by default instead of test unit

Just add rspec-rails into the Gemfile. Nothing else needed.

group :development, :test do
  gem 'rspec-rails'