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.sanitize_sql(["AND column1 = ?", "two's"], '')
But it is not safe because I expose protected method. What is a better way to do it?
You can just use:
ActiveRecord::Base::sanitize_sql(string)
ActiveRecord::Base.connection.quote
does the trick in Rails 3.x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With