Ruby on Rails 项目中缺少模板博客/索引 [英] Missing template blogs/index on Ruby on Rails project

查看:44
本文介绍了Ruby on Rails 项目中缺少模板博客/索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的一个项目,我时不时地收到此异常:

For one of my projects I'm getting this exception every now and then:

ActionView::MissingTemplate:缺少模板博客/索引,带有 {:handlers=>[:rxml, :erb, :builder, :rjs, :haml, :rhtml], :formats=>["image/jpeg","image/pjpeg", "image/png", "image/gif"], :locale=>[:en, :en]} 在视图路径 "/var/www/keeponposting/releases/20110403083651/app/views"

ActionView::MissingTemplate: Missing template blogs/index with {:handlers=>[:rxml, :erb, :builder, :rjs, :haml, :rhtml], :formats=>["image/jpeg", "image/pjpeg", "image/png", "image/gif"], :locale=>[:en, :en]} in view paths "/var/www/keeponposting/releases/20110403083651/app/views"

似乎有人从不是图片的网址请求图片:

It seems someone is requesting an image from a URL that isn't an image:

HTTP_ACCEPT "图像/jpeg、图像/pjpeg、图像/png、图像/gif"

HTTP_ACCEPT "image/jpeg, image/pjpeg, image/png, image/gif"

有什么想法可以做什么吗?我是否必须为其中一个实现一个处理程序并返回"来摆脱这个异常,或者有更好的方法来处理它吗?

Any ideas what to do about it? Do I have to implement a handler for one of those and return "" to get rid of this exceptions or is there a better way to handle it?

现在我也明白了:

ActionView::MissingTemplate:缺少模板博客/索引,带有 {:formats=>["text/*"], :handlers=>[:rjs, :haml, :rhtml, :erb, :rxml, :builder], :locale=>[:en, :en]} 在视图路径/var/www/keeponposting/releases/20110415040109/app/views"

ActionView::MissingTemplate: Missing template blogs/index with {:formats=>["text/*"], :handlers=>[:rjs, :haml, :rhtml, :erb, :rxml, :builder], :locale=>[:en, :en]} in view paths "/var/www/keeponposting/releases/20110415040109/app/views"

无论请求什么格式,都没有办法发回 HTML 吗?

Isn't there a way to send back HTML no matter what format is requested?

推荐答案

我用这个新的 Rails 3.1 选项修复了这个问题(几分钟前 - 到目前为止,一切都很好):

I fixed this issue (a few minutes ago – so far, so good) with this new Rails 3.1 option:

config.action_dispatch.ignore_accept_header = true

此 Rails 问题中所述.这在 config/application.rb 中.

As mentioned in this Rails issue. That goes in config/application.rb.

我在 RSpec 请求测试中这样测试它(使用 Capybara):

I tested it like so in a RSpec request test (using Capybara):

it "should not break with HTTP_ACCEPT image/*;w=320;h=420 from iPhone" do
  page.driver.header "Accept", "image/*;w=320;h=420"
  visit "/some/path"
  page.should have_content("Some content")
end

这篇关于Ruby on Rails 项目中缺少模板博客/索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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