简体   繁体   中英

error :Only get requests are allowed

i get this exception

ActionController::MethodNotAllowed: Only get requests are allowed.

please can any one give solution for this

This error means you are trying to post/put/delete to a path that only accepts GET requests. You need to confirm that your route and the path and/or form method you are using match up.

This error occurs when you have defined a standard route and a client is trying to connect to the route using a HTTP method different than GET or POST.

Usually, this is caused by clients using the Microsoft Office Protocol Discovery. These clients send an OPTION request which is not supported by Rails.

You can fix the problem in multiple ways:

  1. ignore the error in your production environment
  2. prevent the error using a before_filter and head 406 in your controller
  3. rescue the error using rescue_from in your controller
  4. prevent the error filtering the request via Rack Middleware
  5. prevent the error blocking non GET/POST/HEAD requests using your webserver

I personally prefer the last option, but it requires you to have administration privileges on the server. Otherwise, the Rack Middleware option is the most efficient way to filter unexpected requests.

How are you trying to get to this page? It looks like you are trying to do some other kind of RESTful call (put, post, delete) and that method. A code snipped of that controller would be really helpful to diagnose the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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