ruby on rails - How to search by id or name in Active Record using meta search? -


i have model, say:

class mymodel <activerecord::base   attr_accessible :id, :name end 

i want search model using meta_search (https://github.com/ernie/meta_search), how can search id or name?

i tried not work:

mymodel.search(id_equals_or_name_contains: 'sample text') 

the meta search document says don't support different match type (https://github.com/ernie/meta_search#ored-conditions), how should achieve this?

are expecting sample text either integer or string? if implement simple conditional using function described here: test if string integer in quotes using ruby?

s = 'sample text' if !!(s =~ /^[-+]?[0-9]+$/)   mymodel.search(id_equals: s.to_i) else   mymodel.search(name_contains: s) end 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -