kirtithorat / carrierwave-crop

Carrierwave extension to crop uploaded images using Jcrop plugin with preview.
MIT License
94 stars 58 forks source link

Add an option to disable auto-generation of `attr_accessor`s? #3

Closed vendethiel closed 9 years ago

vendethiel commented 10 years ago

Hey,

I just wanted to know if you'd be okay with an option to disable the auto-generation of the attr_accessors for the X_crop_Y attributes. My use case needs me to save those, and I'd rather not have some glue code to save them in the model.

kirtithorat commented 10 years ago

I didn't quite get your use-case. It would be great if you could share an example. Also, do you mean to save crop_x and crop_y attributes in the database? And what about crop_w and crop_h? Virtual attributes or database fields?

vendethiel commented 10 years ago

Sorry - I save them all. The "x_crop_y" means "ATTR_crop_xywh". I need to keep these to crop through later uploaded images (and try to recognize the entity associated to them). Thanks

marckohlbrugge commented 9 years ago

I'm running into a problem using this gem with CarrierWave::Backgrounder and I think it's due to these virtual attributes not being persisted through Delayed::Job.

@vendethiel Would you mind sharing your workaround so I can see whether that solves the issue for me? Thank you in advance.

vendethiel commented 9 years ago

Uhm, I don't remember exactly; but I'll check tomorrow if I remember to.

vendethiel commented 9 years ago
  def update(attributes)
    with_transaction_returning_status do
      assign_attributes(attributes)
      %w(x y h w).each do |pos|
        write_attribute(pos, attributes["image_crop_#{pos}"])
      end

      save
    end
  end