Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails, remove quotes from around active record value in query

Have a query that is failing because the scope is running a query like this :'%'email'%' The internal quotes are causing the problem, how can I get rid of them?

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)}
like image 556
John Avatar asked Nov 27 '25 13:11

John


1 Answers

scope :has_permission, 
      lambda { |email| where("locations.permissions LIKE ?", "%#{email}%") }

There's a way to do this with AREL, too, with a matches("%#{email}%") but I'm not sure of the syntax to get to the nested permissions.

like image 70
Dave Newton Avatar answered Nov 30 '25 03:11

Dave Newton