Rails ActionView :: MissingTemplate for templates that should not exist

I accidentally get this error when creating specific IP addresses on the root path. The rails application does not support formats :formats=>[:gif, "image/x-xbitmap", :jpeg, "image/pjpeg", "application/x-shockwave-flash", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "application/msword"], so this error seems to be expected if a request is made for them. I assume that someone or some bot is trying to launch an exploit against the site - how can I redirect or redirect these requests back to the route path, so that the error is not generated?

ActionView::MissingTemplate: Missing template front_page/index, application/index with {:locale=>[:en], :formats=>[:gif, "image/x-xbitmap", :jpeg, "image/pjpeg", "application/x-shockwave-flash", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "application/msword"], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb, :jbuilder]}. Searched in:
  * "/app/app/views"
  * "/app/vendor/bundle/ruby/2.0.0/gems/activeadmin-1.0.0.pre2/app/views"
  * "/app/vendor/bundle/ruby/2.0.0/gems/kaminari-0.16.3/app/views"
  * "/app/vendor/bundle/ruby/2.0.0/gems/devise-3.5.2/app/views"

  File "/app/vendor/bundle/ruby/2.0.0/gems/actionview-4.2.4/lib/action_view/path_set.rb", line 46, in find
  File "/app/vendor/bundle/ruby/2.0.0/gems/actionview-4.2.4/lib/action_view/lookup_context.rb", line 121, in find
  File "/app/vendor/bundle/ruby/2.0.0/gems/actionview-4.2.4/lib/action_view/renderer/abstract_renderer.rb", line 18, in find_template

Full error here

+4
source share
2 answers

To achieve the desired result in your comment:

constraints :format => "html" do
  resources ...
end

Or if you need more flexibility:

# application_controller.rb
ApplicationController < ActionController::Base
  before_action :check_format!
  ...
  def check_format!
    unless request.format == :html
      render :nothing status: :bad_request
    end
  end
  ...
end

, , ...

, respond_to , - . , , ..

,

, unless explicitly stated, .

+4

, , - :

def index
   ...
  respond_to do |format|
    format.html
    format.all { render status: :bad_request }
  end
end
+3

All Articles