#5 √ resolved
Gaius Centus Novus

@file is always nil after save

Reported by Gaius Centus Novus | March 31st, 2008 @ 07:06 PM

I'm trying to run the following unit test, but it keeps failing.

class PaperclipUser < ActiveRecord::Base
  has_attached_file :avatar, 
                    :styles => { :medium => "300x300>",
                                   :thumb  => "100x100>" },
                    :default_style => :medium,
                    :path => ":rails_root/public/images/:class/:id/:attachment/:style/:basename.:extension",
                    :url => "/images/:class/:id/:attachment/:style/:basename.:extension"
end
...
class PaperclipTest < Test::Unit::TestCase
  def setup
    png = File.new(File.join(File.dirname(__FILE__), ['lib', 'user_suit.png']))
      assert File.exists?(png.path)
      @user_with_avatar = PaperclipUser.create!(:email => 'clarence@example.com', :avatar => png)
  end

  def test_url
    assert_equal '/images/PaperclipUsers/#{@user_with_avatar.id}/avatars/medium/user_suit.png', @user_with_avatar.avatar.url
  end
end

If I don't save (PaperclipUser.new instead of .create!), @file exists and @user_with_avatar.avatar.url returns almost the correct path (@user_with_avatar.id is nil, so that segment doesn't exist).

If I do save, @user_with_avatar.avatar? returns false and @user_with_avatar.avatar.url returns the default URL.

I've attached a diff that seems to clear things up, but I'm not entirely sure it's the right solutions.

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Attachments