Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 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...

like image 788
johan Avatar asked Apr 19 '11 01:04

johan


People also ask

How do I fix request-URI too long?

In the case of the 414 Request-URI Too Large error, the problem is clear: the URLs being passed to the server are too big. To fix it, you'll need to change your Apache or Nginx server settings. This doesn't take too long, and once you're done, you should be back up and running.

What is URI too large?

The HTTP 414 URI Too Long response status code indicates that the URI requested by the client is longer than the server is willing to interpret.

What is a request-URI?

The Request-URI is a Uniform Resource Identifier (section 3.2) and identifies the resource upon which to apply the request. Request-URI = "*" | absoluteURI | abs_path | authority. The four options for Request-URI are dependent on the nature of the request.


1 Answers

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.

like image 85
Brett Bender Avatar answered Oct 11 '22 13:10

Brett Bender