ActionView::MissingTemplate:缺少模板(试图呈现不存在的 :mobile 格式) [英] ActionView::MissingTemplate: Missing template (Trying to render nonexistent :mobile format )

查看:86
本文介绍了ActionView::MissingTemplate:缺少模板(试图呈现不存在的 :mobile 格式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 index.js 可以从桌面正常触发,但是当我尝试从 Mobile Safari 打开时出现以下错误.

I have an index.js in place which is fired ok from desktop but gives the following error when I try to open from Mobile Safari.

ActionView::MissingTemplate: Missing template ads/thumbs/index, application/index with {:locale=>[:es, :en], :formats=>[:mobile], :handlers=>[:erb, :builder, :haml]}. Searched in: * "/app/app/views" * "/app/vendor/bundle/ruby/1.9.1/gems/devise-1.5.2/app/views" * "/app/app/views"

当文件夹中没有这样的文件时,我不确定它为什么要寻找 :formats=>[:mobile].

I'm not sure why it is looking for a :formats=>[:mobile] when there's no such a file in the folder.

尝试通过手机登录 devise 后也会发生同样的事情.我试图渲染一个不存在的 create.mobile.haml 文件.

Same thing happens after trying to sign in with devise from mobile phone. I tries to render a nonexistent create.mobile.haml file.

附言有没有办法让:移动 视图在未找到时回退默认的 :html 视图?这会成功.

P.S. Is there a way to make :mobile views to fallback default :html views when not found? That would make the trick.

推荐答案

这是一个简单的解决方案.

Here's a simple solution.

class ApplicationController
    ...
    def formats=(values)
        values << :html if values == [:mobile]
        super(values)
    end
    ...
end

事实证明,Rails (3.2.11) 已经为 :js 格式的请求添加了 :html 回退.这是 ActionView::LookupContext#formats=

It turns out Rails (3.2.11) already adds an :html fallback for requests with the :js format. Here's ActionView::LookupContext#formats=

# Override formats= to expand ["*/*"] values and automatically
# add :html as fallback to :js.
def formats=(values)
  if values
    values.concat(default_formats) if values.delete "*/*"
    values << :html if values == [:js]
  end
  super(values)
end

所以你可以自己覆盖 #formats= 并且它不会比现有的 Rails 实现更粗暴和笨拙.

So you can override #formats= yourself and it will be conceivably no more gross and hacky than the existing Rails implementation.

这篇关于ActionView::MissingTemplate:缺少模板(试图呈现不存在的 :mobile 格式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆