简体   繁体   中英

ActionController::RoutingError (No route matches [GET] “/assets/images/control_top.png”): in rails 3.2.8

Background image is not uploaded in my view page.showing this error.

ActionController::RoutingError (No route matches [GET] "/assets/images/control_top.png")

what can i do to resolve this problem?

In production env, Rails will not be responsible for serving static assets. Therefore, you are getting this error.

This is controlled by this setting in config/environment/production.rb in your application:

config.serve_static_assets = false

You can set to that true

or try this

rake assets:precompile 

command (compiles and copies images, css and js from app/assets to public/.

If you upgrade to a new version of Rails (Rails 4 and Rails 3.2.16 come to mind), and you suddenly start to see this error, it is likely that your stylesheet is pointing to the non-fingerprinted, non-cached version of the files. If you are using the asset pipeline, in order to take advantage of it, you need to use the new helpers that point to the fingerprinted, cached version of the files. To do so, you'll need to either embed erb in your css file, or use sass.

Incorrect (uses sass):

.class
  background: url('asset.png') no-repeat

Correct (uses sass):

.class
  background: image-url('asset.png') no-repeat

For more info, see here: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

Might help someone , i tried all the answers and forgot the most basic thing to do . Clearing the browser cache , once done i was good to go :)

你必须运行这个命令

rake assets:precompile

I kept using the asset pipeline, but had to change the hard coded url's that I used as follows (for my development environment):

I updated my /config/application.rb to use the asset pipeline:

config.assets.enabled = true

I changed all of my images urls to point to '/assets/image_without_old_image_directory_name.jpg'

so for example my images used to be in /public/images/xxx.jpg. I moved them to /app/assets/images/xxx.jpg. I changed the img src from /images/xxx.jpg to /assets/xxx.jpg

I ended up not needing to do the asset precompile, and simply removed all visible aspects of the asset pipeline in /public and in /tmp, and it just worked (for development).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM