From 37633ac23d3cdf024fa6df08832389dc4b053cd5 Mon Sep 17 00:00:00 2001 From: Kaito Date: Mon, 8 Aug 2011 12:29:32 +0800 Subject: [PATCH] put layout object as embeded obj in design. have bug with solving uploading file --- app/models/design.rb | 2 +- app/models/layout.rb | 5 ++++- app/views/admin/designs/_form.html.erb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/design.rb b/app/models/design.rb index f24705273..add424a12 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 - mount_uploader :layout, DesignFileUploader + embeds_one :layout mount_uploader :structure_css, DesignFileUploader embeds_many :themes diff --git a/app/models/layout.rb b/app/models/layout.rb index 8b6f79578..96f2a1141 100644 --- a/app/models/layout.rb +++ b/app/models/layout.rb @@ -2,7 +2,7 @@ class Layout < DesignFile embedded_in :design - + attr_reader :content field :name, :index => true references_many :children, :class_name => "Item" has_many :layout_parts @@ -11,6 +11,9 @@ class Layout < DesignFile validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/ validates_uniqueness_of :name + def content + self.file.read + end def self.exist_one? Layout.count > 0 end diff --git a/app/views/admin/designs/_form.html.erb b/app/views/admin/designs/_form.html.erb index 43f8e3893..a07cc0712 100644 --- a/app/views/admin/designs/_form.html.erb +++ b/app/views/admin/designs/_form.html.erb @@ -18,7 +18,7 @@

<%= f.label "layout", t('admin.layout') %> <% if @design.layout.blank? %> - <%= f.file_field :layout %> + <%= f.file_field :layout_file %> <% else%> <%= File.basename (Design.all.last.layout.url) %> <% end %>