diff --git a/app/models/post.rb b/app/models/post.rb index 8fd537511..baf592c7f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -16,6 +16,7 @@ class Post < ActiveRecord::Base before_save :set_tag_counts before_validation :initialize_uploader, :on => :create before_validation :parse_pixiv_id + before_validation :blank_out_nonexistent_parents belongs_to :updater, :class_name => "User" belongs_to :approver, :class_name => "User" belongs_to :uploader, :class_name => "User" @@ -760,6 +761,12 @@ class Post < ActiveRecord::Base m.extend(ClassMethods) end + def blank_out_nonexistent_parents + if parent_id.present? && parent.nil? + self.parent_id = nil + end + end + def validate_parent_does_not_have_a_parent return if parent.nil? if !parent.parent.nil? diff --git a/app/views/posts/partials/show/_notices.html.erb b/app/views/posts/partials/show/_notices.html.erb index 378515713..9ab1d7e88 100644 --- a/app/views/posts/partials/show/_notices.html.erb +++ b/app/views/posts/partials/show/_notices.html.erb @@ -46,7 +46,7 @@ <% end %> -<% if post.parent_id %> +<% if post.parent_id && post.parent %>