开发者

Conditional :with using thinking_sphinx

开发者 https://www.devze.com 2023-03-03 21:15 出处:网络
I have the following line in my controller @articles = Article.search \'pancakes\', :with => {:author_id => params[:id]}

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开发者_JS百科 being a valid params[:id]

Thanks


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

精彩评论

暂无评论...
验证码 换一张
取 消