app/models/almanac/post.rb in almanac-0.5.0 vs app/models/almanac/post.rb in almanac-0.5.1
- old
+ new
@@ -14,10 +14,11 @@
validates_uniqueness_of :slug
validates_presence_of :body, :if => lambda {|_| _.published }
before_save :author=
after_initialize :set_written_at
+ after_initialize :check_slug
acts_as_taggable
self.per_page = 10
@@ -46,9 +47,16 @@
end
private
def set_written_at
self.written_at ||= Date.today if new_record?
+ end
+
+ private
+ def check_slug
+ if self.published
+ self.slug ||= self.id
+ end
end
def author=
@author = Almanac.user_class.constantize.find(self.author_id)
end
\ No newline at end of file