Class: SimpleBlog::SimplePost

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
SimpleContentManagement::ContentText
Defined in:
app/models/simple_blog/simple_post.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



31
32
33
# File 'app/models/simple_blog/simple_post.rb', line 31

def destroy
	update_attribute :deleted, true
end

#tags_listObject



18
19
20
# File 'app/models/simple_blog/simple_post.rb', line 18

def tags_list
	tags.pluck("name").join ","
end

#tags_list=(tags_list) ⇒ Object



22
23
24
25
26
27
28
29
# File 'app/models/simple_blog/simple_post.rb', line 22

def tags_list= tags_list
	tag_names = tags_list.split %r{\s*,\s*}
	existing_tags = SimpleBlog::SimplePostTag.where(name: tag_names).all
	existing_tag_names = existing_tags.map &:name
	self.tags = (existing_tags + tag_names.map{ |tag_name|
		SimpleBlog::SimplePostTag.create(name: tag_name) unless existing_tag_names.include? tag_name
	}.compact)
end

#to_paramObject



14
15
16
# File 'app/models/simple_blog/simple_post.rb', line 14

def to_param
	"#{id}-#{title.parameterize}"
end