put layout object as embeded obj in design. have bug with solving uploading file

This commit is contained in:
Kaito 2011-08-08 12:29:32 +08:00
parent 706ec745c3
commit 37633ac23d
3 changed files with 6 additions and 3 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
mount_uploader :layout, DesignFileUploader embeds_one :layout
mount_uploader :structure_css, DesignFileUploader mount_uploader :structure_css, DesignFileUploader
embeds_many :themes embeds_many :themes

View File

@ -2,7 +2,7 @@ class Layout < DesignFile
embedded_in :design embedded_in :design
attr_reader :content
field :name, :index => true field :name, :index => true
references_many :children, :class_name => "Item" references_many :children, :class_name => "Item"
has_many :layout_parts has_many :layout_parts
@ -11,6 +11,9 @@ class Layout < DesignFile
validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/ validates_format_of :name, :with => /^[0-9a-zA-Z\-_]+$/
validates_uniqueness_of :name validates_uniqueness_of :name
def content
self.file.read
end
def self.exist_one? def self.exist_one?
Layout.count > 0 Layout.count > 0
end end

View File

@ -18,7 +18,7 @@
<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 %> <%= f.file_field :layout_file %>
<% else%> <% else%>
<%= File.basename (Design.all.last.layout.url) %> <%= File.basename (Design.all.last.layout.url) %>
<% end %> <% end %>