Rails 3.1 提供来自供应商/资产/图像的图像 [英] Rails 3.1 serving images from vendor/assets/images

查看:29
本文介绍了Rails 3.1 提供来自供应商/资产/图像的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些外部图像(由 jQuery 插件使用)放入我的 Rails 3.1 应用程序中的供应商/资产/图像.问题是,当我尝试以下操作时:

I am trying to put some external images (used by a jQuery plugin) to vendor/assets/images in my Rails 3.1 app. Problem is that when I try something like:

<%= image_tag "ui-bg_flat_75_ffffff_40x100.png" %>

我收到一个错误:

No route matches [GET] "/assets/ui-bg_flat_75_ffffff_40x100.png"

我检查了我的 Rails.application.config.assets.paths 并列出了这些目录:

I checked my Rails.application.config.assets.paths and it list these dirs:

..../app/assets/images
..../app/assets/javascripts
..../app/assets/stylesheets
..../vendor/assets/images
..../vendor/assets/stylesheets
..../.rvm/gems/ruby-1.9.2-p180@mygems/gems/jquery-rails-1.0.9/vendor/assets/javascripts

如您所见,/vendor/assets/images 列在此处.如果我将我的图片放到 app/assets/images 中,一切都会正常.

As you can see /vendor/assets/images is listed there. If I put my image to app/assets/images everything works.

我认为新的资产管道应该遍历所有资产目录并在找到它的任何地方提供请求的文件.

I thought that new asset pipeline was supposed to go through all assets dirs and serve requested file wherever it finds it.

有人知道这里有什么问题吗?

Does anyone knows what's the problem here?

推荐答案

在创建 vendor/assets/images 目录后,我不得不重新启动 Rails 服务器.在此之前,我看到了与您相同的错误(没有路由匹配 [GET]").

I had to restart my rails server after creating the vendor/assets/images directory. Before this, I was seeing the same error as you ("No route matches [GET]").

我的猜测是 rails 服务器不会检查这些目录,如果它们在第一次启动时不存在.当您打开 rails 控制台来诊断问题时,您会得到一个新的 rails 实例,它知道目录,这只会增加混乱.

My guess is that the rails server does not check these directories if they did not exist when it was first started. When you open a rails console to diagnose the issue, you get a new instance of rails which knows about the directory, which only adds to the confusion.

这篇关于Rails 3.1 提供来自供应商/资产/图像的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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