错误RequestURITooLarge搜索ruby

时间:2015-01-14 13:34:42

标签: ruby-on-rails ruby date search

这里的事情:我在表单中有多个搜索字段。但是当我尝试进行多次搜索时,我得到了错误RequestURITooLarge ...我想知道它是否存在避免此问题的方法。每次填写文本框或日期字段时,都会增加网址并收到错误。我也尝试了一个重置​​按钮,但只是清理文本字段。这里有代码供您理解我使用的方法,也许会以某种方式帮助您。韩国社交协会!

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  

索引

<%= 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 %>  

控制器

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  

1 个答案:

答案 0 :(得分:1)

webrick服务器的MAX_URI_LENGTH仅设置为2083个字符。访问长度超过此限制的url会抛出WEBrick :: HTTPStatus :: RequestURITooLarge异常。

尝试切换到其他服务器:

#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