Hi I am using paperclip for image uploading. the thing is, when the user login with fb, it is displaying the profile picture from fb, once he is logged in, he can change the profile picture in the app. but the changed picture is not displaying. and i have default picture stored, that is displaying for the users registered with email. How can display new uploaded photo.
My usermodel is,
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb
=> "100x100#" }
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.fullname = auth.info.name
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.image = auth.info.image
user.password = Devise.friendly_token[0,20]
user.skip_confirmation! unless user.confirmed?
end
end
My application helper is
module ApplicationHelper
def avatar_url(user)
if user.image
user.image
else
"/images/missing.png"
end
end
end
My edit view
<div class="row">
<label class="col-xs-4" for="avatar">Profile picture</label>
<div class="col-xs-8">
<%= f.file_field :avatar %>
</div>
</div>
My show view is,
<%= image_tag avatar_url(@user), class: "avatar-full" %>
Aucun commentaire:
Enregistrer un commentaire