pingu
pingu

Reputation: 8827

Conditional :with using thinking_sphinx

I have the following line in my controller

@articles = Article.search 'pancakes', :with => {:author_id => params[:id]}

and it works fine as long as I have a params[:id] specified, but if I don't, it fails with

searchd error (status: 1): invalid or truncated request

So my question is, is there anyway to have the :with => {:author_id => params[:id]} conditional on their being a valid params[:id]

Thanks

Upvotes: 0

Views: 243

Answers (1)

thefugal
thefugal

Reputation: 1214

ts_options = {}
ts_options[:with] = {:author_id => params[:id]} if params[:id]
@articles = Article.search 'pancakes', ts_options

Upvotes: 3

Related Questions