sunspot を使用して SEO フレンドリーな URL を作成するにはどうすればよいですか?
これから検索を変換したい:
http://localhost:3000/restaurant?utf8=&search=newyork
このようなものに:
http://localhost:3000/restaurant/newyork
sunspot を使用して SEO フレンドリーな URL を作成するにはどうすればよいですか?
これから検索を変換したい:
http://localhost:3000/restaurant?utf8=&search=newyork
このようなものに:
http://localhost:3000/restaurant/newyork
ルーター:
match '/restaurant/:q' => 'restaurants#search'
コントローラ:
class RestaurantsController < ApplicationController
def search
@search = Restaurant.search do
keywords params[:q]
end
@restaurants = @search.results
end
end
その URL を生成するような方法でフォームを送信することは、もう少し設計上の裁量に任されています。カスタム URL を作成してリダイレクトするために、デフォルトの送信アクションをインターセプトするために Javascript を使用する必要がある場合があります。