From 278938a52d565388ba8d577d550f1aa579422078 Mon Sep 17 00:00:00 2001 From: chris2tof Date: Mon, 8 Aug 2011 17:51:37 +0800 Subject: [PATCH] Fixed: layout.file is saved when the design is created --- app/models/design.rb | 10 +++------- app/models/layout.rb | 6 ------ app/views/admin/designs/_form.html.erb | 5 ++++- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/models/design.rb b/app/models/design.rb index e8bda480..1851b07d 100644 --- a/app/models/design.rb +++ b/app/models/design.rb @@ -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 diff --git a/app/models/layout.rb b/app/models/layout.rb index d62eabb7..6b540378 100644 --- a/app/models/layout.rb +++ b/app/models/layout.rb @@ -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 diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb index ccfe3e77..9c4bce40 100644 --- a/app/views/admin/designs/_form.html.erb +++ b/app/views/admin/designs/_form.html.erb @@ -18,7 +18,10 @@

<%= 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 %>