How to disable Rails RoutingError stacktrace printout in Production log files? How to disable Rails RoutingError stacktrace printout in Production log files? ruby-on-rails ruby-on-rails

How to disable Rails RoutingError stacktrace printout in Production log files?


You could add a catch all route after all your other routes that would catch this stuff and render a controller/action of your choosing:

match '*' => 'errors#not_found'

You could even choose to only match .asp or whatever if you wanted:

match '*.:format' => 'errors#not_found', :constraints => {:format => /(asp|zip|rar)/i}


Rails 4 and 5 answer:

match '*any', to: 'not_found#anything', via: [:get, :post]

To match a wildcard parameter, it must have a name assigned to it - any in this case.

class NotFoundController < ApplicationController  def anything    Logger.new('log/not_found.log').info(request.fullpath)    # To render nothing:    # head :not_found #Rails 5    # render nothing: true, status: :not_found # for Rails 4    #To render 404 page    render file: 'public/404.html', status: :not_found, layout: false  endend