diff --git a/app/models/design.rb b/app/models/design.rb index f2470527..add424a1 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 8b6f7957..96f2a114 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 43f8e389..a07cc071 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 %>