Search code examples
ruby-on-railsrubyactiverecord

Undefined method #sanitize for ActiveRecord::Base


I just upgraded to Rails 5.1.1 and am receiving this error.

NoMethodError (undefined method `sanitize' for ActiveRecord::Base:Class):

The stack traces back to this code

like_search_term = ActiveRecord::Base::sanitize("%#{escaped_search_term}%")

Has this method been removed or changed in the new Rails upgrade?


Solution

  • Yes, indeed, it appears to be removed.

    Sanitize was never part of the public API of the framework. As we didn't need it in the framework anymore, we removed. The recommended ways to sanitize raw SQL for use in execute statements were the public API for that http://api.rubyonrails.org/classes/ActiveRecord/Sanitization/ClassMethods.html