ruby on rails - How to use paperclip with devise to add profile photo? -
creating pinterest-like app users can create pin image, title, , description easy paperclip.
but i'm having trouble modifying paperclip docs when want use way upload profile picture when i'm using devise.
any tips?
try following code.
in users/registrations/new.html.erb view file add following code.
<%= form_for @user, url: users_path, html: { multipart: true } |f| %> <%= f.file_field :avatar %> <% end %>
in devise's user model add following code.
class user < activerecord::base has_attached_file :avatar, :styles => { :large => "400x400>", :medium => "200x200>", :thumb => "100x100>" } validates_attachment :avatar, :presence => true, :content_type => { :content_type => "image/jpeg", :message => "only jpeg formats allowed" } end
in controller.
def create @user = user.create( user_params ) end private def user_params params.require(:user).permit(:avatar) end
Comments
Post a Comment