Module: CarrierWave::Uploader::Mountable
- Included in:
- Base
- Defined in:
- lib/carrierwave/uploader/mountable.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#mounted_as ⇒ Object
readonly
Returns the value of attribute mounted_as.
Instance Method Summary collapse
-
#index ⇒ Object
Returns array index of given uploader within currently mounted uploaders.
-
#initialize(model = nil, mounted_as = nil) ⇒ Object
If a model is given as the first parameter, it will be stored in the uploader, and available through
#model
.
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/carrierwave/uploader/mountable.rb', line 5 def model @model end |
#mounted_as ⇒ Object (readonly)
Returns the value of attribute mounted_as.
5 6 7 |
# File 'lib/carrierwave/uploader/mountable.rb', line 5 def mounted_as @mounted_as end |
Instance Method Details
#index ⇒ Object
Returns array index of given uploader within currently mounted uploaders
39 40 41 |
# File 'lib/carrierwave/uploader/mountable.rb', line 39 def index model.__send__(:_mounter, mounted_as).uploaders.index(self) end |
#initialize(model = nil, mounted_as = nil) ⇒ Object
If a model is given as the first parameter, it will be stored in the uploader, and available through #model
. Likewise, mounted_as stores the name of the column where this instance of the uploader is mounted. These values can then be used inside your uploader.
If you do not wish to mount your uploaders with the ORM extensions in -more then you can override this method inside your uploader. Just be sure to call super
Parameters
- model (Object)
-
Any kind of model object
- mounted_as (Symbol)
-
The name of the column where this uploader is mounted
Examples
class MyUploader < CarrierWave::Uploader::Base
def store_dir
File.join('public', 'files', mounted_as, model.permalink)
end
end
31 32 33 34 |
# File 'lib/carrierwave/uploader/mountable.rb', line 31 def initialize(model=nil, mounted_as=nil) @model = model @mounted_as = mounted_as end |