【问题标题】:Render status: 403 causes "Missing template" error渲染状态:403 导致“缺少模板”错误
【发布时间】:2015-09-09 14:09:40
【问题描述】:

我在before_filter 中有一些方法,我尝试渲染status: 403。然后我得到:

Missing template v1/examples/index, v1/base/index, application/index with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}.

但是,我可以渲染 nothing: truetext: 'some text' 而不会出现此错误。我做错了什么?

【问题讨论】:

  • 发布代码。看起来您正在尝试呈现您没有的 403 页面。检查您的公用文件夹。
  • 见鬼,我应该渲染空的 json hash + status...谢谢!

标签: ruby-on-rails ruby-on-rails-4 render status http-status


【解决方案1】:

没有你的代码很难说,但听起来你想做以下事情:

render json: {}, status: :forbidden

【讨论】:

  • 如此频繁的错误。如果请求格式未被识别为 json,它将搜索模板 - 您的解决方案将修复它。它应该被批准
猜你喜欢
  • 2018-02-26
  • 2015-11-21
  • 2014-02-13
  • 1970-01-01
  • 2013-05-13
  • 1970-01-01
  • 2016-08-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多