5

I'm trying to implement a manual crop for a web application I'm working on, and I have this so far:

  version :croppedversion do
    process :manualcrop => [model.crop_x, model.crop_y, model.crop_h, model.crop_w]
  end

  process :resize_to_limit => [600, 600]

  def manualcrop(x,y,h,w)
    manipulate! do |img|
      img = img.crop(x,y,h,w)
    end
  end

The problem is that model is turning up as nil. From the documentation I've read this would be the correct way to go about it.

Any suggestions? I've moved the call to cropping into a callback in the model for now, but would really like for it to reside inside carrierwave

2 Answers 2

0

I ran into a similar issue. I had

attr_accessor :crop_x, :crop_y, :crop_w, :crop_h

but forgot to include them the crop variables in the attr_accessible. By doing

attr_accessible :description, :image, :crop_x, :crop_y, :crop_w, :crop_h

I was able to get the model crop variables. I dont know if this would solve your issue because you're describing the model returning nil rather than the crop methods.

1
  • 1
    I ran into that issue as well, as I am horrible about keeping my attr_accessible's straight, but alas, it is the model that is nil.
    – Kelend
    May 17, 2011 at 5:14
0

I struggled very much with my object being nil in CarrierWave when trying to access model data.

For me, the issue was in my controller. This doesn't look like it applies too much to your situation, but I was running a query by doing: model.user.foo - It would come up nil if I was immediately assigning this user to the model after creating the object.

3
  • Where inside your carrierwave uploader where you successfully accessing model? I can only seem to access it inside the path method and not anything custom (such as my own processors)
    – Kelend
    Jun 25, 2011 at 3:29
  • Unfortunately it was within the path method I fixed my own issue and no where else.
    – Kombo
    Jun 27, 2011 at 22:27
  • But the question is: what you did to fix the issue. show some code please.
    – geekdeepak
    Apr 11, 2013 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.