Ruby-on-rails ActionController::RoutingError(没有路由匹配 [GET] "/assets/images/control_top.png"):在 rails 3.2.8 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14519997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:19:54  来源:igfitidea点击:

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

ruby-on-rails

提问by Inaccessible

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

背景图片未上传到我的视图页面。显示此错误。

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

ActionController::RoutingError (没有路由匹配 [GET] "/assets/images/control_top.png")

what can i do to resolve this problem?

我该怎么做才能解决这个问题?

回答by Sachin R

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

在生产环境中,Rails 将不负责提供静态资产。因此,您收到此错误。

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

这由应用程序中 config/environment/production.rb 中的此设置控制:

config.serve_static_assets = false

You can set to that true

你可以设置为true

or try this

或者试试这个

rake assets:precompile 

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

命令(将图像、css 和 js 从 app/assets 编译并复制到 public/.

回答by Aaron Gray

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.

如果您升级到新版本的 Rails(想到 Rails 4 和 Rails 3.2.16),并且突然开始看到此错误,则很可能您的样式表指向的是文件。如果您正在使用资产管道,为了利用它,您需要使用指向文件的指纹缓存版本的新助手。为此,您需要在 css 文件中嵌入 erb,或者使用 sass。

Incorrect (uses sass):

不正确(使用 sass):

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

Correct (uses sass):

正确(使用 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

有关更多信息,请参见此处:http: //guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

回答by Caffeine Coder

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 :)

可能会帮助某人,我尝试了所有的答案,但忘记了最基本的事情。清除浏览器缓存,完成后我很高兴:)

回答by Asnad Atta

you have to run this command

你必须运行这个命令

rake assets:precompile

回答by Taylored Web Sites

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

我一直在使用资产管道,但不得不更改我使用的硬编码 url,如下所示(对于我的开发环境):

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

我更新了我的 /config/application.rb 以使用资产管道:

config.assets.enabled = true

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

我将所有图片网址更改为指向“/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

例如,我的图像曾经在 /public/images/xxx.jpg 中。我将它们移至 /app/assets/images/xxx.jpg。我将 img src 从 /images/xxx.jpg 更改为 /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).

我最终不需要进行资产预编译,只需删除 /public 和 /tmp 中资产管道的所有可见方面,它就可以工作(用于开发)。