Rubytastic
Rubytastic

Reputation: 15491

Carrierwave implementing default_url correctly?

I have tried for several hours on several moments to get my carrierwave setup correctly working but haven't be able to get this issue fixed.

Correctly loading a image version + show the default_url version when no image present. Using below code at this moment because default_url does not work. I call below method like show_avatar(@profile.id) from any view to display user picture.

profile_helper.rb:
  def show_avatar(id)
    @profile = User.find(id).profile rescue nil
    image_tag @profile.photos.first.file_url(:img_112x135)
  rescue
    image_tag ("/assets/avatars/img_122x145.png")    <---- This is my default image 
  end

I know this is not the right way to do it? What would be the correct clean way of having this functionality implemented?

Upvotes: 1

Views: 174

Answers (1)

Dipak Panchal
Dipak Panchal

Reputation: 6036

try this

image_tag("/assets/img_122x145.png")  # if image in assets/avatars folder
or
image_tag("/assets/avatars/img_122x145.png") # if image in assets/images/avatars folder

Upvotes: 1

Related Questions