userden
userden

Reputation: 1683

default_url not working with CarrierWave (Rails4)

I would like to display a default image, if the user doesn't upload an image. Here is my picture_uploader.rb and I uploaded default.png to /images/fallback. But I can't get it to work. Any tips, what could I try next?

class PictureUploader < CarrierWave::Uploader::Base

  include CarrierWave::MiniMagick
  version :thumb do
    process :resize_to_fill => [150, 150]
  end

  # Provide a default URL as a default if there hasn't been a file uploaded:
  def default_url
    "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  end
end

Upvotes: 0

Views: 518

Answers (1)

cortex
cortex

Reputation: 5206

According to your default_url, the name of your image should be thumb_default.png:

[2] pry(main)> version_name = 'thumb'
=> "thumb"
[3] pry(main)> [version_name, "default.png"].compact.join('_')
=> "thumb_default.png"

Upvotes: 2

Related Questions