0

I've trying to do a mongoid query in my rails project. I thought this should work but it returns RegexpError: unmatched close parenthesis: /)/i This is my attempt

search = params[:name]
users = User.any_of({first_name: /#{search}/i}, { last_name: /#{search}/i}).to_a

I really dont know what I'm doing wrong. Any help appreciated

2
  • Use /#{Regexp.escape(search)}/i Commented Feb 10, 2017 at 10:37
  • Thanks! It works perfect. I have just realized the issue raised because someone did a search with parameters ")" . So mongo was treating it as parenthesis instead of as string. Thanks a lot! Commented Feb 10, 2017 at 10:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.