Search code examples
ruby-on-railsrails-activerecorddynamic-findersruby-on-rails-4

Dynamic bang finders in Rails 4


Rails 4 is getting rid of dynamic finders, so

User.find_by_hash(hash)

becomes

User.where(hash: hash) # .first

Okay, not a big deal. But what is the best way to deal do with dynamic bang finders like User.find_by_hash!(hash) since there is no where!() method? Rails 4 Release Notes conveniently avoid this.

Update: It plainly says: "All dynamic methods EXCEPT for find_by_... and find_by_...! are deprecated."

Either the pages has changed since or I was blind when reading it.


Solution

  • It plainly says: "All dynamic methods EXCEPT for find_by_... and find_by_...! are deprecated."