Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails paginate(kaminari)中用于搜索%_Ruby On Rails_Kaminari - Fatal编程技术网

Ruby on rails paginate(kaminari)中用于搜索%

Ruby on rails paginate(kaminari)中用于搜索%,ruby-on-rails,kaminari,Ruby On Rails,Kaminari,我在搜索页面上有paginate(kaminari),如果我用%搜索某个东西,比如“50%折扣”,我会得到页面http://some.domain.com/50%25+折扣其中paginate有错误的URL(未转义%),如: http://some.domain.com/50%+折扣?第2页 我做错什么了吗?还是宝石里的虫子 谢谢%是URL中的一个特殊字符,不是吗?在将查询传递到url之前,您需要使用搜索方法对其进行清理 我相信您可以使用gemstringex中提供的String类的方法来清理搜

我在搜索页面上有paginate(kaminari),如果我用%搜索某个东西,比如“50%折扣”,我会得到页面
http://some.domain.com/50%25+折扣
其中paginate有错误的URL(未转义%),如:
http://some.domain.com/50%+折扣?第2页

我做错什么了吗?还是宝石里的虫子


谢谢

%是URL中的一个特殊字符,不是吗?在将查询传递到url之前,您需要使用搜索方法对其进行清理

我相信您可以使用gemstringex中提供的String类的方法来清理搜索词

从那里可以看到github页面

"10% off if you act now".to_url => "10-percent-off-if-you-act-now"
编辑:

你需要有这样的东西(这不是很干净,但它给了你一个想法)

你会表现得像对待普通物体一样,但你从来没有真正保存过它。如果需要,您甚至可以将:create方法的名称更改为parse,但这样内置的rails帮助程序和逻辑就可以工作了。

我的解决方案是

paginate@entities,:params=>{:keyword=>CGI.escape(@keyword)}

route.rb中
我有


match”/:keyword“=>“route#index”,:keyword=>/.*/

感谢您提供解决方案的变体。也许我会用它,如果bug在几天内无法修复的话。试着在谷歌上搜索“如果你现在行动就可以打9折”,这是正常的逃避这个问题更多的是元代码,但是的,这就是重点。而且它不是卡米纳里的虫子在URL中是不安全的。因此,将一个传递到url将导致问题,因此您必须以某种方式使其安全,如上所述。
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