Rails:使用单/双qoute在数据库中保存字符串,不带反斜杠

时间:2018-04-06 15:33:53

标签: ruby-on-rails ruby

我需要使用字段record.name = "blah'"保存记录。它一直保存为"blah\'",这给了我一个错误。我尝试将"'"替换为"\'" .gsub(" ' ","\\\\'"),但将字符串保存为"test1\\\'"。如何在不收到错误的情况下使用qoutes保存名称?

在保存或更新之前,我输出字符串并以这种方式显示:"blah'" In the controller it is being saved this way: @ bewirtung.save!`

当我得到保存在服务器日志中的查询时,我将此字符串视为:`“blah'\”'。

错误是这样的:

'Remote SQLExecDirect: [Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface]Syntax Error: UPDATE "Object": UPDATE "Object" SET "name" = 'blah\'', "LastChange" = '2018<< ??? >>-04-06 17:28:' from CONNECT:
  mysql2-0.3.21-x86 (mingw32) lib/mysql2/client.rb:80:in `block in query'
  mysql2-0.3.21-x86 (mingw32) lib/mysql2/client.rb:79:in `query'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:309:in `block in execute'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract_adapter.rb:484

0 个答案:

没有答案