Reputation: 759
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?
Upvotes: 2
Views: 5052
Reputation: 4551
Just simply return "default.png" in default_url method.
def default_url
"default.png"
end
Upvotes: 2
Reputation: 7948
Another approach:
ActionController::Base.helpers.asset_path("default.png")
Upvotes: 3
Reputation: 2310
This is an asset pipeline issue.
Try getting /assets/default.png
(drop the images/)
More information here: http://guides.rubyonrails.org/asset_pipeline.html
Upvotes: 6