jnicklas/carrierwave — Issue #530: Uploader #model's attributes not populated in conditional version method
Author: cblunt
Created: 2011-11-18 13:29:27+00:00
State: open

I have an uploader with a conditional version which is created depending on an attribute of the model. I'm trying to access properties of `#model` in the conditional method, but although the model exists, it's attributes are not yet populated (they are all `nil`):

```ruby
class MyUploader < CarrierWave::Uploader::Base
version :thumb, :if => :attached_to_page? do
process :resize_to_fill => [32, 32]
end

def attached_to_page?(uploaded_file)
# raise model.to_yaml proves that all attributes on the model are nil
model.attachable_type.underscore.to_sym == :page
end
end

# Simple model classes provided for demonstration
class Attachment < ActiveRecord::Base
mount_uploader :image, MyUploader

belongs_to :attachable, :polymorphic => :true
end

class Page < ActiveRecord::Base
has_many :attachments, :as => :attachable, :dependent => :destroy

accepts_nested_attributes_for :attachable
end
````

Is there any way to have CarrierWave allow the model's attributes to be populated prior to creating conditional versions in this way?