Home Ask Login Register

Developers Planet

Your answer is one click away!

Jeramae Bohol February 2016

How to use paperclip with devise to add profile photo?

Creating a pinterest-like app where users can create a pin with an image, title, and description is easy with paperclip.

But I'm having trouble modifying the paperclip docs when I want to use it as a way to upload a profile picture when I'm using devise.

Any tips?


Dheeresha February 2016

Try the following code.

In your users/registrations/new.html.erb view file add the following code.

<%= form_for @user, url: users_path, html: { multipart: true } do |f| %>
  <%= f.file_field :avatar %>
<% end %>

In your devise's user model Add the 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" }


In your controller.

def create
  @user = User.create( user_params )


def user_params

Post Status

Asked in February 2016
Viewed 1,286 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life