views:

34

answers:

1

This seems like a common task, I'm sure others have come across it.

If my controller says this :

def index
  s = Sunspot.search Organization do |query|
    query.keywords params[:q] unless params[:q].blank?
    query.with(:searchable).equal_to(params[:filter_by] == 'published' ? 'true' : false) if params[:filter_by]
  ..

How do I:

.. through a link, make it change its query.with(:searchable) statement to query.with(:has_no_deals) ?

Here's my starter link that doesn't work, because the old query.with(:searchable) is not overwritten:

= link_to 'Has No Deals', url_for(:overwrite_params => { :filter_by => 'dfgsdgsdf', :page => nil })
A: 

Just add this little baby in your controller

query.with(:searchable).equal_to(params[:filter_by] == 'published' ? 'true' : false) if params[:filter_by] == ( 'published' || 'unpublished' )

query.with(:has_no_deals).equal_to(params[:filter_by] == 'has_no_deals' ? 'true' : false) if params[:filter_by] == 'has_no_deals'
Trip