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

查看:54
本文介绍了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列在其中.如果我将图片放到应用程序/资产/图片中,一切正常.

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天全站免登陆