如何在Rails的单引号之前加一个反斜杠?

时间:2018-01-23 22:38:01

标签: ruby-on-rails ruby string neo4j

我输入如下:

str = "Jane\'s very good..."
# => "Jane's very good..."

str = "Jane\\'s very good..."
# => "Jane\\'s very good..."

如何使用单引号获取str,如:

"Jane\'s very good..."

我正在使用neo4j(NoSQL)架构进行社交媒体文字分析;

words = txt.split(' ')
                notIncludingWords = Array.new
                sqlParameter=''
                words.each do |word|
                    if(Word.where(name:word).first.nil?)
                       notIncludingWords.push(word)
                    else
                        sqlParameter+=",'"+word+"'"
                    end
                end
                sqlParameter = sqlParameter[1..sqlParameter.length-1]

...(交易......)

table = Word.query_as(:w).where("w.name IN["+sqlParameter+"]")

                    RecordCount = table.return("SUM(w.recordcount) AS recordcount").first.recordcount.to_f

...(交易)

当我尝试运行时,它会给我一个错误;

Cypher error:
  [36mNeo.ClientError.Statement.SyntaxError[0m: Invalid input 'ı': expected whitespace, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ']' (line 1, column 71 (offset: 70))
"MATCH (w:`Word`) WHERE (w.name IN['26','yıl','önce','bugün','Hasan'ın','doğum','günüdür']) RETURN SUM(w.recordcount) AS recordcount"

1 个答案:

答案 0 :(得分:1)

你实际上是对的。 irb只是返回转义的表示。

e.g。

>> str = "\\"
=> "\\" 

>> str.length
=> 1 

>> puts str
\
=> nil

>> puts "Jane\\'s very good..."
=> Jane\'s very good...