有一个查询失败,因为范围正在运行如下查询:'%'email'%'
内部引号导致问题,我该如何摆脱它们?Rails,从查询中的活动记录值附近删除引号
user.rb (User Model)
#it's checking a text field to see if it contains the email address
@locations = Location.has_permission(self.email)
location.rb (Location Model)
scope :has_permission, lambda { |email| where("locations.permissions LIKE '%?%'",email)}
它似乎工作。有一个问题。 ||是什么?做?你为什么有第二组内部报价? – John
@John:'||'是SQL中的字符串连接运算符,因此''%'|| ? ||在Ruby中,'%'最终与''%'+ email +'%''相同。 –
使用插值法对此有利吗?还是更安全? –