app/models/page.rb in manifest-rails-0.0.4 vs app/models/page.rb in manifest-rails-0.1.0

- old
+ new

@@ -1,34 +1,39 @@ class Page < ActiveRecord::Base extend FriendlyId friendly_id :title, use: :slugged - before_save :set_template_path - after_create :create_template_file - after_update :move_template_file - after_destroy :remove_template_file + after_create :create_template + after_update :rename_template + after_destroy :remove_template validates :title, :slug, uniqueness: true validates :title, presence: true validates :slug, presence: true, on: :update has_many :content_blocks - private + default_scope order('title') - def set_template_path - @old_template_path = attribute_was(:template_path) - self.template_path = "#{Rails.root}/app/views/pages/#{self.slug}.html.erb" + def template_path + template_path_from_slug(slug) end - def create_template_file + private + + def create_template %x(touch #{self.template_path}) end - def move_template_file - %x(mv #{@old_template_path} #{self.template_path}) + def rename_template + old_template_path = template_path_from_slug(slug_was) + %x(mv #{old_template_path} #{template_path}) end - def remove_template_file - %x(rm #{self.template_path}) + def remove_template + %x(rm #{template_path}) + end + + def template_path_from_slug(slug) + "#{Rails.root}/app/views/pages/#{slug}.html.erb" end end