Sounds like params[:query] isn’t always being set? Essentially, you want to avoid calling gsub on nil. So, that could be done like this:
query = params[:query] query.gsub!(/\s+/, ‘ | ‘) unless query.nil? User.search query Or, `to_s` on nil returns an empty string: User.search params[:query].to_s.gsub(/\s+/, ‘ | ‘) Hope this helps. — Pat > On 4 Dec 2014, at 8:13 am, C Wilson <[email protected]> wrote: > > Can using gsub work when using `query` as params? > > User.search(params[:query].gsub(/\s+/, ' | ') > > returns NoMethodError: undefined method `gsub' for nil:NilClass. > > However if I switch it to params[:search] it works perfect with gsub. But in > this situation I need gsub with query as params. > > Anyone have any ideas? > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at http://groups.google.com/group/thinking-sphinx > <http://groups.google.com/group/thinking-sphinx>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/thinking-sphinx. For more options, visit https://groups.google.com/d/optout.
