Skip to content

Instantly share code, notes, and snippets.

@uu59
Created January 18, 2017 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uu59/97f37636695c432c7c43cb95eab34f24 to your computer and use it in GitHub Desktop.
Save uu59/97f37636695c432c7c43cb95eab34f24 to your computer and use it in GitHub Desktop.
class SqlEruby < Erubis::EscapedEruby
def escaped_expr(expr)
"#{self.class.to_s}.escape(#{expr})"
end
def self.escape(str)
ActiveRecord::Base.connection.instance_variable_get(:@connection).escape(str.to_s)
end
end
erb = SqlEruby.new("<%= @hi %>")
erb.evaluate(hi: %Q|!"#$%&'()`*?>+_[@p]|) #=> "!\"\#$%&''()`*?>+_[@p]\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment