How to sanitize sql fragment in Rails

前端 未结 6 574
南方客
南方客 2021-02-01 13:28

I have to sanitize a part of sql query. I can do something like this:

class << ActiveRecord::Base
  public :sanitize_sql
end

str = ActiveRecord::Base.sani         


        
6条回答
  •  清酒与你
    2021-02-01 14:32

    As of rails 5 the recomended way is to use: ActiveRecord::Base.connection.quote(string)

    as stated here: https://github.com/rails/rails/issues/28947

    ActiveRecord::Base::sanitize(string) is deprecated

提交回复
热议问题