Will_Paginate with Sunspot - Ruby on Rails
Hey all,
I’ve just gone through setting up will_paginate with sunspot 1.3, just thought I’d share in case anyone else has any troubles/improvements.
In my case I’m setting it up on a products model.
#products.rb
#Sunspot/Search
searchable do
text :title, :boost => 5
text :description
end
#products_controller.rb
#Products search
def search
#Create vars
search = Product.search do
fulltext params[:search]
paginate :page => params[:page] || 1, :per_page => 2
end
#Retrieve results
@products = search.results
#Create responses
respond_to do |format|
format.html { render 'index' }
end
end
#Search partial - _search.html.erb
'products', :action => 'search', :method => :get do %>
'25', :class => 'search' %>
#Product display page - index.html.erb
"products/product_line", :locals => {:product => product} %>
false, :params => { :search_text => params[:search_text] } %>
Well that’s about it, if anyone needs any further info or has any tips, leave a comment and I’ll get back to you asap.
Useful post! Thank you.
No worries, thanks for the feedback
Great post! Thanks for this.
No problem, thanks for the feedback.
Thanks for this! Was tearing hair out trying to figure out how to work this with Sunspot...
lol no worries, ran into quite a few problems myself :D
How can I search from my homepage and have sunspot return results on another view?