but also wanted to be able to search by keyword using a form submission.
We ended up redirecting within the controller action to the canonical path if the search param ('q') was present. This code might help.
class SearchController < ApplicationController
def index
if params[:q]
return redirect_to search_url(:keywords => keywords_from_params)
end
@models = Model.search(keywords_from_params, params)
end
private
def keywords_from_params
params[:keywords].blank? ? params[:q].to_s.split(/\s+/) : params[:keywords]
end
end
# config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.root :controller => :search, :action => :index
map.search 'search/*keywords', :controller => :search, :action => :index
end
--
~ Sam Goldstein