Problem saving user profile image with paperclip

I'm trying to add avatars to Devise users with Paperclip. I've gone through the steps in your lesson for setting up Paperclip, but for some reason the file isn't getting saved, so it is still the default image after trying to update the user profile. I'll post the details below.

Posted about 5 years ago by Nate
Posted about 5 years ago by Nate

I checked out the server logs and noticed this error:

ActionController::RoutingError (No route matches [GET] "/system/users/profile_images/000/000/005/medium/profile-image.png"):

0
Posted about 5 years ago by Alex Yang

The problem isn't with the steps you followed - it's an issue of where the file is being saved. Are you using the paperclip-dropbox gem for image hosting?

0
Posted about 5 years ago by Nate

No, I haven't changed any of the save settings.

0
Posted about 5 years ago by Alex Yang

Try it again after setting up image hosting - you'll need to do this anyway once your app goes live.

0
Posted about 5 years ago by Nate

I've added s3 hosting. The image still isn't showing up, and it's doing something else strange. It's only saving the original to s3, and not the medium or thumbnail sizes.

0
Posted about 5 years ago by Alex Yang

Double-check 1) your model file containing your paperclip settings and 2) your S3 configuration. It's likely one of these two.

0
Posted about 5 years ago by Nate

Ok. One other question. Because I set up Paperclip before for another model, can you imagine any way it might have some effect on what I'm trying to do now?

0
Posted about 5 years ago by Alex Yang

It's really hard to say - depends on how you set up paperclip and image hosting - but yes it could. See if you can think of a way to break this problem down. For example, follow the Etsydemo tutorial and use the paperclip-dropbox gem for image hosting. If that works, then you know it's your paperclip settings that are causing the problem.

0
Posted about 5 years ago by Nate

Thanks for all the tips. I was able to find the problem. I looked at the actual links produced by s3 on the management console. I noticed that the server was different than just s3.amazonaws.com. So I had to add to the has_attached_file line in the controller.

I added :s3_host_name => "s3-us-west-2.amazonaws.com"

Working how it should now!

0
Posted about 5 years ago by Nate

1. I ran rails g paperclip user profile_image

2. To the model, user.rb, I added the following:

has_attached_file :profile_image, :style => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "missing.png"

validates_attachment_content_type :profile_image, :content_type => /\Aimage\/.*\Z/

3. I added this to application_controller.rb:

def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :username
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:username, :email, :password, :current_password, :profile_image)}
end

4. Then I added this to the view:
<%= image_tag(current_user.profile_image.url(:thumb)) %>

I actually looked at the html, and the image is there, but it isn't showing up. It shows a missing image.

0