petfreshman
petfreshman

Reputation: 523

Paperclip not saving photo

I have looked through many similar questions and tried the solutions with no success. I am using rails 3 and paperclip 3. I have successfully installed ImageMagick as the tutorial on the paperclip github instructs.

In my model:

has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/profile_photo_store/missing.png"
attr_accessible :photo

In my database I have added these columns:

:photo_file_name, :photo_content_type, :photo_file_size, :photo_updated_at

In my edit view:

<%= form_for(@user, :url => user_path, :html => { :multipart => true }) do |f| %>
  <div class="field">
    <b>Add a Photo</b><br />
    <%= f.file_field :photo %>
  </div><br />
<% end %>

In my show view

<%= image_tag @user.photo.url(:medium) %>

I can tell that the photo is being sent because I see it going through via Firebug. Yet the missing.png is still displaying. Where does paperclip save the files? What am I doing wrong.

Upvotes: 0

Views: 2133

Answers (3)

Antonio Jha
Antonio Jha

Reputation: 1309

Please check if the strong parameter in the controller accepts :photo.

Upvotes: 0

petfreshman
petfreshman

Reputation: 523

Couldn't resolve this answer so I switched to carrierwave...afterwards I had a similar issue. Reinstalled ImageMagick using package manager rather than build from source which solved it. Apparently when built from the source, the bin file is saved in /usr/local/bin, which my rails app couldn't see.

Upvotes: 1

rails_has_elegance
rails_has_elegance

Reputation: 1692

In Rails 3.2 the paperclip attachments are stored in your public folder public/system/users/[photo or avatar...]/... . You can check if they went through and were saved. I don't see any obvious error in your code. You can use this migration just to make sure:

class AddAttachmentAvatarToUsers < ActiveRecord::Migration
  def self.up
    add_column :users, :photo_file_name, :string
    add_column :users, :photo_content_type, :string
    add_column :users, :photo_file_size, :integer
    add_column :users, :photo_updated_at, :datetime
  end

  def self.down
    remove_column :users, :photo_file_name
    remove_column :users, :photo_content_type
    remove_column :users, :photo_file_size
    remove_column :users, :photo_updated_at
  end
end

And you can either remove the default photo code, or edit it to "/images/..." and create an image folder in your public folder, cause that's where paperclip is looking for the file. It seems that paperclip still is configured the 'old' way (all assets being in the public folder): In user model

has_attached_file :photo, :styles => { :medium => "200x200>", :thumb => "60x60>" },
                         :default_url => "/images/default_:style_avatar.png"

If you want you can try to just write:

<%= form_for(@user) do |f| %>
...

Upvotes: 0

Related Questions