我解析文件中的一些数据。 然后使用.split(“ |”)拆分数据,并将其保存到数组变量中。 当y时,使用ActiveRecord where查询内的数组字段。 它不会返回任何内容。
我尝试了插值,但这没用。
fields = cob.to_s.encode('UTF-8',:invalid => :replace).split("|")
#fields[0] = "19992"
.
.
.
@ticket = Somerecord.where(:no_ticket => fields[0].to_s).take!
# this doesnt work
#but the following code works.
@ticket = Somerecord.where(:no_ticket => '11992').take!
@ticket = Somerecord.where(:no_ticket => "11992").take!
ActiveRecord::RecordNotFound (Couldn't find Record with [WHERE "crb"."no_ticket" = $1]):
SELECT "crb".* FROM "crb" WHERE "crb"."no_ticket" = $1 LIMIT $2 [["no_ticket", "11992"], ["LIMIT", 1]]