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...
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.
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.
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.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With