How to specify Ruby regex when using Active Record in Rails?

前端 未结 3 801
礼貌的吻别
礼貌的吻别 2020-12-16 16:08

To get all jobs which invoice_number is a pure number I do:

Job.where(\"invoice_number REGEXP \'^[[:digit:]]+$\'\")

Is it poss

3条回答
  •  时光取名叫无心
    2020-12-16 16:25

    Your best bet is either Regexp#tos or Regexp#source or Regexp#inspect.

    But I can't think of why you would want to do this -- Ruby doesn't make it easy to compose Regexps programmatically (which is the only reason I can think of why one might want to compose at one level and submit it to another).

提交回复
热议问题