开发者

How to fix Request-URI Too Large error in rails 3?

开发者 https://www.devze.com 2023-02-27 02:29 出处:网络
Im having an error that says: Request-URI Too Large Actually I\'m trying to add a search function on my experimental rails 3 app which开发者_JAVA技巧 accepts a string and a date as search paramete

Im having an error that says:

Request-URI Too Large

Actually I'm trying to add a search function on my experimental rails 3 app which开发者_JAVA技巧 accepts a string and a date as search parameters. For some reasons when I click the submit button to do the search the URL in my browser is very long and Im having this error I mentioned above.

Here is the code for my model trap.rb:

class Trap < ActiveRecord::Base

 def self.search(empcode, date_entry)
  if empcode and date_entry
   where('empcode LIKE ? and date_entry = ?', "%#{empcode}%", "#{date_entry}")
  else
   scoped
  end
 end
end

In the controller traps_controller.rb:

class TrapsController < ApplicationController

 def index
  @traps = Trap.search(params[:search_empcode], params[:search_date_entry])

  respond_to do |format|
   format.html # index.html.erb
   format.xml  { render :xml => @traps }
  end
 end

 .
 .
 .
end

And in the view index.html.erb:

<h2>TRAP 1.0</h2>

<%= form_tag traps_path, :method => 'get' do  %>
 <p>
  Employee Code: <%= text_field_tag :search_empcode, params[:search_empcode] %>
  Date Entry: <%= date_select :search_date_entry, params[:search_date_entry] %>
 </p>

 <p class="buttons"> <%= submit_tag "Search", :name => nil %></p>
<% end %>

<table>
 <tr>
  <th>Empcode</th>
  <th>Date entry</th>
  <th></th>
  <th></th>
  <th></th>
 </tr>

 <% @traps.each do |trap| %>
 <tr>
  <td><%= trap.empcode %></td>
  <td><%= trap.date_entry %></td>
  <td><%= link_to 'Show', trap %></td>
  <td><%= link_to 'Edit', edit_trap_path(trap) %></td>
  <td><%= link_to 'Destroy', trap, :confirm => 'Are you sure?', :method => :delete %></td>
 </tr>
 <% end %>
</table>

<br />

<%= link_to 'New Trap', new_trap_path %>

Can somebody tell me what's wrong with this one? If you know some alternatives. Pls help...


I had this error authenticating against google's openID actually, they redirected me back to my own app with a few hundred GET params. I didn't figure out what the issue was, but instead of using the built in Rails server, I started using thin instead and the error magically disappeared. Must just be the way the server handles them internally.

Try gem install thin then thin start from your rails root directory.


If you want to keep using webbrick just go to lines 246 and 247 in ruby-version/lib/ruby/version/webrick/httprequest.rb and change the bytesize numbers, I just doubled them:

@request_line = read_line(socket, 2048) if socket
if @request_line.bytesize >= 2048 and @request_line[-1, 1] != LF
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号