Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-3.1sunspotsunspot-solr

rails sunspot gem friendly SEO url's?


How does one get SEO friendly url's in sunspot?,

The method of search form is GET as suggested from the rails docs, but now i have a very long query string that looks terrible, is it possible to have it something like

/search/param1/bla/param2/bla 

instead of the long

?search&param1=somevalue&param2=someval2

Solution

  • You could modify your search route to include the params. Something like this within your routes.rb:

      match '/search/:param1/:param2' => 'search_controller#search_action', :as => :search_with_params, :via => :get
    

    Then a user would visit:

    /search/value1/value2

    Which gives you params[:param1] and params[:param2] to access the values from the url.

    If those 2 params are not required for all searches I believe you would also need a route just for the search action:

    match '/search' => 'search_controller#search_aciton', :as => :search, :via => :get