Carrierwave default image doesn't display

[亡魂溺海] 提交于 2019-12-08 05:53:51

问题


I'm trying to have a default image display in my Rails 3.2 application. I've followed the instructions on the Carrierwave github page and have looked through several Stackoverflow posts. But, for some reason it's still not working.

Here is my code:

In my photo_uploader.rb file I've enabled this:

def default_url
  "/images/" + [version_name, "default.png"].compact.join('_')
end

In my form and show views I'm accessing the image like this:

<%= image_tag @user.photo.url %>

The path to my image is:

/app/assets/images/default.png

In my application.rb I've added the following line because that's supposed to allow static assets be served up:

config.serve_static_assets = true

However, my server is showing the following when the page is loaded:

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

I've also tried re-compiling my assets.

Any ideas on what I'm doing wrong?


回答1:


This is an asset pipeline issue.

Try getting /assets/default.png (drop the images/)

More information here: http://guides.rubyonrails.org/asset_pipeline.html




回答2:


Another approach:

ActionController::Base.helpers.asset_path("default.png")



回答3:


Just simply return "default.png" in default_url method.

def default_url
  "default.png"
end


来源:https://stackoverflow.com/questions/16800511/carrierwave-default-image-doesnt-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!