From 00fe407be045a5b6cf8269965c0fd35a44094741 Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 8 Mar 2009 22:31:00 +0100 Subject: added date selector for published_at. Also removed the part that reset the published_at attribute to Time.now. Some cleanups --- app/models/node.rb | 5 +---- app/models/page.rb | 25 ++++++------------------- app/views/nodes/edit.html.erb | 5 +++++ 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/app/models/node.rb b/app/models/node.rb index 7f2bca6..d2db4ba 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -59,7 +59,6 @@ class Node < ActiveRecord::Base def create_new_draft user empty_page = self.pages.new empty_page.user = user - empty_page.clone_attributes_from self.head self.draft = empty_page @@ -70,11 +69,9 @@ class Node < ActiveRecord::Base def publish_draft! if self.draft self.head = self.draft + self.head.save! self.draft = nil self.save! - - self.head.published_at = Time.now - self.head.save! else nil end diff --git a/app/models/page.rb b/app/models/page.rb index a27ccfc..ae2f998 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -19,7 +19,7 @@ class Page < ActiveRecord::Base before_save :rewrite_links_in_body # Security - attr_accessible :title, :abstract, :body, :template_name + attr_accessible :title, :abstract, :body, :template_name, :published_at # Class Methods @@ -59,24 +59,6 @@ class Page < ActiveRecord::Base end # Instance Methods - - def clone_attributes_from page - return nil unless page - - self.tag_list = page.tag_list.join(", ") - - locale_before = I18n.locale - - I18n.available_locales.each do |l| - next if l == :root - I18n.locale = l - self.title = page.title - self.abstract = page.abstract - self.body = page.body - end - - I18n.locale = locale_before - end def public_template_path File.join(PUBLIC_TEMPLATE_PATH, template_name) @@ -106,8 +88,13 @@ class Page < ActiveRecord::Base def clone_attributes_from page return nil unless page + # Clone untranslated attributes + self.tag_list = page.tag_list.join(", ") self.template_name = page.template_name + self.published_at = page.published_at + + # Clone translated attributes locale_before = I18n.locale diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb index 929bbf6..d230f5c 100644 --- a/app/views/nodes/edit.html.erb +++ b/app/views/nodes/edit.html.erb @@ -13,6 +13,11 @@ <%= f.error_messages %> <% fields_for @draft do |d| %> + +

+ <%= d.label :published_at %>
+ <%= d.datetime_select :published_at %> +

<%= d.label :template_name %> <%= d.select :template_name, custom_page_templates %> -- cgit v1.3