Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recreate_versions! model variable points to wrong instance object #1015

Closed
waynehoover opened this issue Mar 5, 2013 · 1 comment

Comments

@waynehoover
Copy link

commented Mar 5, 2013

In the Readme it states

"The model variable points to the instance object the uploader is attached to." But I have found this not to be true when using recreate_versions!.

I have some attr_accessor's set up on my model and those are not available to me in the uploader class when recerate_versions! is called, yet they are available in the class when I call avatar.model.attr_accessor_name

Below is my code. avatar.model in the user class gives correct results. But in the AvatarUploader class itself model returns nil for the accessors when they are set for what should be that instance. This makes me believe that recreate_versions! isn't passing the correct instance.

model:

class User < ActiveRecord::Base
  def crop_avatar
      if crop_x.present?
        self.avatar.model.crop_x.present? ##=> correctly works
        avatar.recreate_versions!
      end
  end
end

uploader:

class AvatarUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
  include Sprockets::Helpers::RailsHelper
  include Sprockets::Helpers::IsolatedHelper

 ...
  version :small do
    process :crop
    process :resize_to_fill => [32, 32]
  end

  def crop
  ##This code here is never run, model.crop_x.present? is always nil, but should be true in some cases. why?
    if model.crop_x.present?
      resize_to_limit(600, 600)
      manipulate! do |img|
        x = model.crop_x
        y = model.crop_y
        w = model.crop_w
        h = model.crop_h
        img.crop "#{w}x#{h}+#{x}+#{y}"
        img
      end
    end
  end

end

By the way I got this technique from railscast-182 if you want code to test, try the sample app he provides there, it is currently broken because of this bug.

@bensie

This comment has been minimized.

Copy link
Member

commented Feb 18, 2014

I'm unable to reproduce this issue. Feel free to post a sample app demonstrating the issue and we can take a look.

@bensie bensie closed this Feb 18, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.