Access the model from inside the Carrierwave bootloader

I am trying to implement manual cropping for the web application I'm working on, and I still have this:

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 the model rises as zero. From the documentation I read, this would be the right way to do this.

Any suggestions? I moved the cropping call to the callback in the model, but I would really like it to be inside the carrier wave

+4
source share
2 answers

I had a similar problem. I had

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

but forgot to include them in crop variables in attr_accessible. Performing

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

I managed to get the crop variables of the model. I don’t know if this will solve the problem, because you are describing a model returning zero, not cropping methods.

0
source

I tried my best to keep my object zero in CarrierWave when trying to access model data.

For me, the problem was in my controller. It does not seem like it affects your situation too much, but I fulfilled the request by executing: model.user.foo - it will come to zero if I immediately assigned this user to the model after creating the object.

0
source

All Articles