Escaping values in Rails (similar to mysql_real_escape_string())

后端 未结 6 1841
我在风中等你
我在风中等你 2020-12-14 00:54

I know about prepared statements, but if I\'m using raw SQL, does ActiveRecord have a way to manually escape values?

Something like this would be nice:



        
6条回答
  •  爱一瞬间的悲伤
    2020-12-14 01:31

    You can do:

    Dude.sanitize("O'Malley")
    

    or

    Dude.connection.quote("O'Malley")
    

    both with the same result: => "'O''Malley'"

提交回复
热议问题