gpt4 book ai didi

ruby-on-rails - Rails ActionView::MissingTemplate 用于不应该存在的模板

转载 作者:行者123 更新时间:2023-12-03 16:01:09 26 4
gpt4 key购买 nike

在从根路径上的某些 IP 地址进行生产时,我随机收到此错误。 rails 应用程序不支持格式 :formats=>[:gif, "image/x-xbitmap", :jpeg, "image/pjpeg", "application/x-shockwave-flash", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "application/msword"]因此,如果为他们提出请求,似乎会出现此错误。我猜有人或某个机器人正试图对该站点运行漏洞利用——我如何将这些类型的请求重定向或路由回路由路径,以便不会产生错误?

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

完整的错误是 here

最佳答案

要在您的评论中获得所需的结果:

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

或者,如果您需要更多的灵活性:
# 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 的桶是非常典型的。在 Controller 中,因为正常行为是尝试提供任何格式。否则,可能会有大量的配置等。

Is there a way to do this for all controller actions unless explicitly stated



所以当你说 unless explicitly stated你有点逆流而上。

关于ruby-on-rails - Rails ActionView::MissingTemplate 用于不应该存在的模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35944734/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com