Search code examples
ruby-on-railsrubygemspaperclipruby-on-rails-plugins

Problems updating Paperclip from plugin to gem


I am apparently having a huge problem switching from the plugin version of Paperclip to the gem version in my app. It's been my impression that there should be no difference whatsoever between a plugin and a gem of a specified version. However, I'm not seeing this as an easy transition at all.

Rails 2.3.11, Ruby 1.8.7

The plugin version I am using is version 2.3.3 and was upgraded on August 2, 2010. Attempting to update this to the gem of the same version basically killed all my tests, not being able to load a factory model which did not have its attachment loaded. It appeared that validate_attachment_content_type was also attempting to validate the attachment presence, and couldn't find it, so everything just started breaking. Again, with the plugin there are no problems and I haven't had any problems in all this time we've been using it. On the other hand, this problem seems to not occur past version 2.3.4. That's a whole other set of problems.

Basically, in all versions from 2.3.4 and up I get the problem below:

can't convert nil into String
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/storage/s3.rb:163:in `extname'
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/storage/s3.rb:163:in `to_file'
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/attachment.rb:94:in `assign'
/home/joshua/.rvm/gems/ruby-1.8.7-p334@paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip.rb:279:in `avatar='
/home/joshua/railscamp/app/app/models/organization.rb:311:in `copy_membership'

in all my tests that access my organization model.

The apparent offending code in this case is attempting to clone a membership model from one organization to another, with the * line being the offending call.

  def copy_membership(membership)
    m = membership.clone
    u = m.user.clone
    u.organization = self
    m.organization = self

    begin
      m.avatar = membership.avatar         *
    rescue RuntimeError
      m.avatar = nil
    end

    m.user = u
    m.save
    m
  end

Does this make any sense to anyone? Why would the plugin work, but the gem of the same version just wrecks everything?

Update: I also don't appear to have any paperclip rake tasks available. Any ideas?


Solution

  • As it turns out, we should have been checking whether the filename is valid or not, rather than depending on a generic runtime error for detecting avatar presence.