【发布时间】:2015-03-17 19:22:49
【问题描述】:
我有以下方法,如果请求是针对 xml、json 或 html 的,则抛出 404。
def render_error(code, status_type = nil)
@error = ErrorMessage.new(code, status_type)
respond_to do |format|
format.any(:html, :json) { render @error.partial, status: @error.status }
format.any { render html: ErrorMessage.new(404).partial }
end
end
这是部分方法
def partial
'messages/show'
end
如果我使用format.any { head 404, "content_type" => 'text/plain' } 而不是format.any { render html: ErrorMessage.new(404).partial },同样的效果。这是我得到的错误。
Missing template errors/index with {:locale=>[:en], :formats=>[:xml], :handlers=>[:erb, :builder, :raw, :ruby, :haml]}
当我请求test.xml
但我想使用程式化的 html 错误。我在这里做错了什么?
【问题讨论】:
-
我们不知道。你的错误是什么?
-
对此我很抱歉。我忘记在此处粘贴错误。现在已经更新了问题。谢谢
标签: ruby-on-rails ruby renderpartial