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)}
Your scope should be building the pattern using string concatenation:
||is the string concatenation operator in SQL so the following:In Ruby, ends up the same as:
This is a question of style, wrapping the email address in percents in Ruby (either with
+or interpolation) yields the same result in the end. Perhaps I’m just more comfortable with SQL than a lot of Rails people.