【发布时间】:2012-11-08 00:00:26
【问题描述】:
如何使用 sunspot 创建 SEO 友好的 url?
我想从这里转换搜索:
http://localhost:3000/restaurant?utf8=&search=newyork
到这样的事情:
http://localhost:3000/restaurant/newyork
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 solr sunspot
如何使用 sunspot 创建 SEO 友好的 url?
我想从这里转换搜索:
http://localhost:3000/restaurant?utf8=&search=newyork
到这样的事情:
http://localhost:3000/restaurant/newyork
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 solr sunspot
路由器:
match '/restaurant/:q' => 'restaurants#search'
控制器:
class RestaurantsController < ApplicationController
def search
@search = Restaurant.search do
keywords params[:q]
end
@restaurants = @search.results
end
end
以生成该 URL 的方式提交表单更多地取决于您的设计判断。您可能需要使用一些 Javascript 来拦截默认提交操作以制作并重定向到自定义 URL。
【讨论】: