简体   繁体   English

错误RequestURITooLarge搜索红宝石

[英]Error RequestURITooLarge searching ruby

Here the thing: I have multiples search fields in my form. 事情在这里:我的表单中有多个搜索字段。 But i got the error RequestURITooLarge when I tried to do a multiples searches...I'm wondering if it is exist a method to avoid this problem. 但是当我尝试进行多次搜索时出现错误RequestURITooLarge ...我想知道它是否存在避免此问题的方法。 Every time you fill the text box or date field increment the url and got the error. 每次您填充文本框或日期字段时,都会增加url并得到错误。 I also tried a reset button but just clean the text fields. 我也尝试过重置按钮,但只清理文本字段。 Here the code for you to understand the method I use and perhaps will help you in some way. 这里的代码供您了解我使用的方法,也许会在某种程度上帮助您。 Tks!! 韩国社交协会!

View_item 查看项目

def self.search(s_codigo, s_den_cont, s_marca)
where("codigo ilike :s_c and den_cont ilike :s_d and marca ilike :s_m", s_c: "%#{s_codigo}%", s_d: "%#{s_den_cont}%", s_m: "%#{s_marca}%")
end

#Search section #2  

def self.search_fec_min(s_codigo, s_den_cont, s_marca, s_fec_min)
where("codigo ilike :s_c and den_cont ilike :s_d and marca ilike :s_m and date_expired >= :s_fmin", s_c: "%#{s_codigo}%", s_d: "%#{s_den_cont}%", s_m: "%#{s_marca}%", s_fmin: "#{s_fec_min}")
end  

index 指数

<%= text_field_tag :s_codigo, params[:s_codigo], placeholder: "Search for cod" %>
<%= text_field_tag :s_den_cont, params[:s_den_cont], placeholder: "Search for Denominación" %>
<%= text_field_tag :s_marca, params[:s_marca], placeholder: "Search brand" %>
<%= date_select :s_fec_min, params[:s_fec_min], placeholder: "Search for date", :include_blank => true %>  

Controller 调节器

if self.is_date(params[:s_fec_min])
@items = View_item.all.order("date_expired ASC").page(params[:page]).per(15).search_fec_min(params[:s_codigo], params[:s_den_cont], params[:s_marca], params[:s_fec_min])     
  elsif (params[:s_codigo] != "" or params[:s_den_cont] != "" or params[:s_marca] != "")
@items = View_item.all.order("date_expired ASC").page(params[:page]).per(15).search(params[:s_codigo], params[:s_den_cont], params[:s_marca])
  else
@items = View_item.all.order("date_expired ASC").page(params[:page]).per(15)
end  

MAX_URI_LENGTH is set to only 2083 characters for webrick server. Webrick服务器的MAX_URI_LENGTH设置为仅2083个字符。 On accessing url of length more than this limit throws WEBrick::HTTPStatus::RequestURITooLarge exception. 在访问长度超过此限制的URL时,将引发WEBrick :: HTTPStatus :: RequestURITooLarge异常。

Try to switch to different server : 尝试切换到其他服务器:

#Gemfile
gem 'thin'

$bundle install 
$ rails s

=> Booting Thin
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:3000, CTRL+C to stop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM