Clean code and workaround mongoid embedded with carrierwave
This commit is contained in:
1 parent
a1391493a3
commit
a571d1dcff
7 files changed
+55
-66
No files matched your search
+11
-13
@@ -38,16 +38,14 @@ class Design
|
||||
# Update or create the attribute_model records
|
||||
def files=(attrs)
|
||||
case attrs.last
|
||||
when 'layout'
|
||||
files = self.layout.build
|
||||
else
|
||||
files = eval(attrs.last)
|
||||
when 'layout'
|
||||
files = self.layout.build
|
||||
else
|
||||
files = eval(attrs.last)
|
||||
end
|
||||
attrs[0].each do |a|
|
||||
if(a[:id]=='' && !a[:file].nil? )
|
||||
if(a[:file]!='')
|
||||
files.build(:file => a[:file], :to_save => true)
|
||||
end
|
||||
if a[:id].blank? && !a[:file].blank?
|
||||
files.build(:file => a[:file], :to_save => true)
|
||||
else
|
||||
files.each do |file|
|
||||
if file.id.to_s == a[:id]
|
||||
@@ -75,6 +73,7 @@ class Design
|
||||
end
|
||||
end
|
||||
if self.layout.to_save
|
||||
self.layout.to_save = false
|
||||
self.layout.save
|
||||
self.layout.parse_urls
|
||||
end
|
||||
@@ -86,12 +85,11 @@ class Design
|
||||
end
|
||||
|
||||
def process_object(object)
|
||||
if object.file.blank?
|
||||
object.to_save = false
|
||||
end
|
||||
if object.to_save
|
||||
object.to_save = false
|
||||
object.save
|
||||
new_object = self.send(object._type.downcase.pluralize).build
|
||||
new_object.file = object.file
|
||||
object.destroy
|
||||
new_object.save
|
||||
end
|
||||
if object.to_destroy
|
||||
object.destroy
|
||||
|
||||
@@ -39,7 +39,7 @@ class Layout < DesignFile
|
||||
names << [html_name, file_name]
|
||||
}
|
||||
names.each do |name|
|
||||
content.gsub!(name[0], name[1])
|
||||
content.gsub!(name[0], name[1]) rescue nil
|
||||
end
|
||||
Dir.mktmpdir('f_path') { |dir|
|
||||
orig_file_name = self.file_filename
|
||||
|
||||
Reference in new issue
Block a user