Fixed: layout.file is saved when the design is created

This commit is contained in:
chris2tof 2011-08-08 17:51:37 +08:00
parent 9cea77430f
commit 278938a52d
3 changed files with 7 additions and 14 deletions

View File

@ -11,7 +11,7 @@ class Design
validates_presence_of :title validates_presence_of :title
validates_presence_of :author validates_presence_of :author
embeds_one :layout,:class_name=>Layout embeds_one :layout
mount_uploader :structure_css, DesignFileUploader mount_uploader :structure_css, DesignFileUploader
embeds_many :themes embeds_many :themes
@ -21,10 +21,6 @@ class Design
after_save :procs_embedded_objects after_save :procs_embedded_objects
after_destroy :del_embedded_objects after_destroy :del_embedded_objects
def layout=(*attrs)
self.files = (attrs << 'layout')
end
def javascripts=(*attrs) def javascripts=(*attrs)
self.files = (attrs << 'javascripts') self.files = (attrs << 'javascripts')
end end
@ -62,14 +58,14 @@ class Design
protected protected
def del_embedded_objects 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| objects.each do |object|
object.destroy object.destroy
end end
end end
end end
def procs_embedded_objects 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| objects.each do |object|
if object.file.blank? if object.file.blank?
object.to_save = false object.to_save = false

View File

@ -3,14 +3,8 @@ class Layout < DesignFile
embedded_in :design embedded_in :design
attr_reader :content attr_reader :content
field :name, :index => true
# references_many :children, :class_name => "Item"
has_many :layout_parts has_many :layout_parts
validates_presence_of :name
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
validates_uniqueness_of :name
def content def content
self.file.read self.file.read
end end

View File

@ -18,7 +18,10 @@
<p> <p>
<%= f.label "layout", t('admin.layout') %> <%= f.label "layout", t('admin.layout') %>
<% if @design.layout.blank? %> <% 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%> <% else%>
<%= File.basename (@design.layout.file.url) %> <%= File.basename (@design.layout.file.url) %>
<% end %> <% end %>