M
M
mlwrm2016-03-29 21:33:05
Ruby on Rails
mlwrm, 2016-03-29 21:33:05

How to set default image in paperclip?

There is a user model.

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  has_many :posts, dependent: :destroy
  has_many :comments, dependent: :destroy
  has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" },
                    default_url: "/images/:style/missing.png"
  validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
end

View code:
<p>
    <strong>Avatar:</strong> <br>
    <%= image_tag @user.avatar.url(:medium) %>
</p>

I did everything according to the documentation https://github.com/thoughtbot/paperclip
If the user does not have an avatar, then it is not displayed. There is a missing.png image in the /assets/images folder, but I get the output
f2a1b182024d452f82e5ab125700fd1e.png
How to solve the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mlwrm, 2016-03-29
@malworm

The solution to this problem is described here:
www.suffix.be/blog/default-image-paperclip
Glad if it helped someone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question