CarrierWave workaround: the files have to be saved manually
This commit is contained in:
1 parent
f73f09ffcf
commit
c3ada90365
8 files changed
+39
-54
No files matched your search
+19
-36
@@ -17,55 +17,38 @@ class Design
|
||||
embeds_many :javascripts
|
||||
embeds_many :images
|
||||
|
||||
after_update :destroy_attrs
|
||||
after_save :save_embedded_objects
|
||||
|
||||
def javascripts=(*attrs)
|
||||
self.attribute_models=(attrs<<'javascripts')
|
||||
self.files = (attrs << 'javascripts')
|
||||
end
|
||||
|
||||
|
||||
def stylesheets=(*attrs)
|
||||
self.attribute_models=(attrs<<'stylesheets')
|
||||
self.files = (attrs << 'stylesheets')
|
||||
end
|
||||
|
||||
|
||||
def images=(*attrs)
|
||||
self.attribute_models=(attrs<<'images')
|
||||
self.files = (attrs << 'images')
|
||||
end
|
||||
|
||||
|
||||
# Update or create the attribute_model records
|
||||
def attribute_models=(attrs)
|
||||
#attribute_models = eval(attributes[:type])
|
||||
# if attributes.original_filename.blank?
|
||||
attribute_models=eval(attrs.last)
|
||||
a=attribute_models.build()
|
||||
a.file=attrs[0]
|
||||
# else
|
||||
# attribute_model = attribute_models.detect {|a| a.id.to_s == attributes[:id].to_s }
|
||||
# attribute_model.update_attributes(attributes)
|
||||
#end
|
||||
end
|
||||
|
||||
def is_built_in?
|
||||
self.built_in
|
||||
end
|
||||
|
||||
def is_disabled?
|
||||
self.disabled
|
||||
end
|
||||
|
||||
def get_enabled_attribute_models
|
||||
self.attribute_models.excludes('disabled' => true)
|
||||
def files=(attrs)
|
||||
files = eval(attrs.last)
|
||||
attrs[0].each do |a|
|
||||
files.build(:file => a[:file], :to_save => true)
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Destroy the i18n_variable for each attribute_models if marked to destroy
|
||||
def destroy_attrs
|
||||
=begin
|
||||
attribute_models.each do |a|
|
||||
if a.should_destroy?
|
||||
a.destroy_i18n_variable
|
||||
def save_embedded_objects
|
||||
[self.stylesheets, self.javascripts, self.images].each do |objects|
|
||||
objects.each do |object|
|
||||
if object.to_save
|
||||
object.to_save = false
|
||||
object.save
|
||||
end
|
||||
end
|
||||
end
|
||||
=end
|
||||
end
|
||||
end
|
||||
@@ -2,5 +2,7 @@ class DesignFile
|
||||
include Mongoid::Document
|
||||
|
||||
mount_uploader :file, AssetUploader
|
||||
|
||||
field :to_save, :type => Boolean
|
||||
|
||||
end
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
class Image<DesignFile
|
||||
|
||||
class Image < DesignFile
|
||||
embedded_in :design
|
||||
end
|
||||
@@ -1,3 +1,3 @@
|
||||
class Javascript<DesignFile
|
||||
|
||||
class Javascript < DesignFile
|
||||
embedded_in :design
|
||||
end
|
||||
@@ -1,5 +1,3 @@
|
||||
class Stylesheet < DesignFile
|
||||
mount_uploader :file, AssetUploader
|
||||
|
||||
embedded_in :design
|
||||
end
|
||||
Reference in new issue
Block a user