Mass updates in rails console

I found this neat little trick in the console to mass update database information.

Just a one liner.

Company.find_all_by_user_id(nil).each do |c| c.user_id=1; end

If you have a shorter snippet I would like to hear from you.


Company.update_all("user_id"=1, "user_id=nil")
This entry was posted in Uncategorized by admin. Bookmark the permalink.

Comments are closed.