我在页面上有页面(kaminari),如果我搜索%像“50%折扣”的东西我得到页http://some.domain.com/50%25+discount
其中页面错误的URL(没有转义% )像: http://some.domain.com/50%+discount?page=2
在页面错误的网址(kaminari)搜索与%
我做错了什么?或者它是宝石中的错误?
谢谢
我在页面上有页面(kaminari),如果我搜索%像“50%折扣”的东西我得到页http://some.domain.com/50%25+discount
其中页面错误的URL(没有转义% )像: http://some.domain.com/50%+discount?page=2
在页面错误的网址(kaminari)搜索与%
我做错了什么?或者它是宝石中的错误?
谢谢
我的解决方案是
paginate @entities, :params => { :keyword => CGI.escape(@keyword) }
route.rb
我有
match "/:keyword" => "route#index", :keyword => /.*/
%是在url中的特殊字符是不是?您需要使用搜索方法在查询传递到url之前清理查询。
我相信你可以使用gem Stringex中提供的String类的方法来清理搜索项。
https://github.com/rsl/stringex
从那里GitHub页面
"10% off if you act now".to_url => "10-percent-off-if-you-act-now"
编辑:
您将需要有这样的事情(这是不是很干净,但它给你的想法)
class SearchesController < ApplicationController
def new
#Form in its view that goes to create via json
end
def create
query = params[:query].to_url
redirect_to "/search/#{query}"
end
def show
#search paged on params[:query]
end
end
路线
resources :searches, :only => [:new, :create, :show], :new => ""
get "/search" => "searches#new", :via => :get
你会表现得像你把它当作一个普通的对象一样对待,但是你永远不会真的保存它。如果需要,甚至可以更改:create方法的名称进行解析,但这种方式内置的rails helper和logic可以工作。
感谢您的解决方案的变体。可能是我会使用它,如果错误不会在几天内修复。 – Alexey
尝试在谷歌搜索“如果你现在采取行动10%”,它正常逃避这个查询 – Alexey
它的更多的元代码,但是这是多数民众赞成的整点。而且它不是kaminari的缺陷。 %在网址中不安全。因此,将一个URL传递给URL会导致问题,所以你必须使它像上面那样安全。 – rovermicrover