Some bots or other external requests cause an ActionController::UnknownFormat
error when redirecting
Is there a catch-all method to add somewhere in application_controller to handle those errors ?
A config spec to add a default method in request (if none specified) ?
Below an example of trace :
An ActionController::UnknownFormat occurred in main#index:
ActionController::UnknownFormat
app/controllers/main_controller.rb:17:in `index'
-------------------------------
Request:
-------------------------------
* URL : http://ownedurl.com/
* HTTP Method: GET
* IP address : 82.xxx.xxx.xxx
* Parameters : {"controller"=>"main", "action"=>"index"}
* Timestamp : 2015-06-07 20:54:32 +0200
* Server : servername
* Rails root : /var/www/ownedurl.com/releases/208
* Process: 29726
A get request would obviously work; yet it makes it occurs.
Experiences on this one appreciated thx a lot
This will handle a request without format :
rescue_from ActionController::UnknownFormat, with: :raise_not_found
def raise_not_found
render(text: 'Not Found', status: 404)
end
You can supply the :format
to your routes itself to tell it what are the formats are valid and which are not.
Read some discussions on this and this answer .
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.