Fixed: layout.file is saved when the design is created
This commit is contained in:
parent
9cea77430f
commit
278938a52d
|
@ -11,7 +11,7 @@ class Design
|
|||
validates_presence_of :title
|
||||
validates_presence_of :author
|
||||
|
||||
embeds_one :layout,:class_name=>Layout
|
||||
embeds_one :layout
|
||||
mount_uploader :structure_css, DesignFileUploader
|
||||
|
||||
embeds_many :themes
|
||||
|
@ -21,10 +21,6 @@ class Design
|
|||
after_save :procs_embedded_objects
|
||||
after_destroy :del_embedded_objects
|
||||
|
||||
def layout=(*attrs)
|
||||
self.files = (attrs << 'layout')
|
||||
end
|
||||
|
||||
def javascripts=(*attrs)
|
||||
self.files = (attrs << 'javascripts')
|
||||
end
|
||||
|
@ -62,14 +58,14 @@ class Design
|
|||
|
||||
protected
|
||||
def del_embedded_objects
|
||||
[self.layout,self.themes, self.javascripts, self.images].each do |objects|
|
||||
[[self.layout],self.themes, self.javascripts, self.images].each do |objects|
|
||||
objects.each do |object|
|
||||
object.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
def procs_embedded_objects
|
||||
[self.layout,self.themes, self.javascripts, self.images].each do |objects|
|
||||
[[self.layout],self.themes, self.javascripts, self.images].each do |objects|
|
||||
objects.each do |object|
|
||||
if object.file.blank?
|
||||
object.to_save = false
|
||||
|
|
|
@ -3,14 +3,8 @@ class Layout < DesignFile
|
|||
embedded_in :design
|
||||
|
||||
attr_reader :content
|
||||
field :name, :index => true
|
||||
# references_many :children, :class_name => "Item"
|
||||
has_many :layout_parts
|
||||
|
||||
validates_presence_of :name
|
||||
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
|
||||
validates_uniqueness_of :name
|
||||
|
||||
def content
|
||||
self.file.read
|
||||
end
|
||||
|
|
|
@ -18,7 +18,10 @@
|
|||
<p>
|
||||
<%= f.label "layout", t('admin.layout') %>
|
||||
<% if @design.layout.blank? %>
|
||||
<%= f.file_field :layout %>
|
||||
<%= fields_for 'design[layout]' do |f| %>
|
||||
<%= f.file_field :file %>
|
||||
<%= f.hidden_field :to_save, :value => true %>
|
||||
<% end %>
|
||||
<% else%>
|
||||
<%= File.basename (@design.layout.file.url) %>
|
||||
<% end %>
|
||||
|
|
Reference in New Issue