开发者

rails3.1 ActionController::RoutingError (No route matches [GET] "/images/up_arrow.gif"):

开发者 https://www.devze.com 2023-04-07 14:13 出处:网络
My stylesheet has: .asc { font-size: 2em; background-image: url(/images/up_arrow.gif); } .desc { background-image: url(/images/down_arrow.gif);

My stylesheet has:

.asc { font-size: 2em; background-image: url(/images/up_arrow.gif); }

.desc { background-image: url(/images/down_arrow.gif); }

The font-size works but the background image (arrow) doesn't. I get ActionController::RoutingError (No route matches [GET] "/images/up_arrow.gif"):

I tried lots of thi开发者_StackOverflow社区ngs in routes but nothing worked.

rails3.1 ActionController::RoutingError (No route matches [GET] "/images/up_arrow.gif"):


Try this:

.asc { font-size: 2em; background-image: url(/assets/up_arrow.gif); }
.desc { background-image: url(/assets/down_arrow.gif); }

That's how I do it in a 3.1 app I'm working on. Your /images is probably mapped to app/public/images.


Finally found that I needed to do the new precompile of assets step. 'I shoulda read the manual'

Compiled assets are put in public/assets directory by default (the destination is defined in config.assets.prefix).

To create compiled versions of your assets use bundle exec rake assets:precompile

If you don't have write access for the production file system, use this task locally and then copy the compiled asset files.

The asset compilation process:

1. Concatenates & compresses all JavaScript files into one master. Uglifier is the default for the process.
2 Compresses (minifies) all CSS files into one master .css file. CSS is compressed by yui by default.
3. Allows for high level languages like coffeescript to use the assets.

Note: It is possible (though not a great idea) to disable the asset pipeline by changing config/application.rb and set
config.assets.enabled = false

You can skip the asset pipeline when creating a new application with the —skip-sprockets option, e.g. rails new appname --skip-sprockets

You can also set config.assets.compile = true This way the assets are only compiled when a request for them is made.


Dumb question perhaps, but are you positive that /images/up_arrow.gif exists?

When you 404 on an public asset in it just falls through to the rails router. It's not really a routing problem; you just get a routing error because there are no routes defined for static assets.


I had this same issue with Rails 3.2.13.

Solution was to modify the css to this:

.asc { font-size: 2em; background-image: url(up_arrow.gif); }
.desc { background-image: url(down_arrow.gif); }
0

精彩评论

暂无评论...
验证码 换一张
取 消