class Admin::Posts::TagsController

Public Instance Methods

create() click to toggle source
# File lib/ecrire/app/controllers/admin/posts/tags_controller.rb, line 13
def create
  @tag = Tag.search_by_name(tag_params[:name]).first
  if @tag.nil?
    @tag = Tag.create(tag_params)
  end

  if @post.tags.include? @tag
    @post.tags = @post.tags.where.not(id: @tag.id)
  else
    @post.tags << @tag
  end

  @post.save!

end
index() click to toggle source
# File lib/ecrire/app/controllers/admin/posts/tags_controller.rb, line 6
def index
  @tags = Admin::Tag.all
  if params.has_key?(:q) && !params[:q].blank?
    @tags = @tags.search_by_name(params[:q])
  end
end
toggle() click to toggle source
# File lib/ecrire/app/controllers/admin/posts/tags_controller.rb, line 29
def toggle
  @tag = Admin::Tag.find(params[:tag_id])
  if @post.tags.include? @tag
    @post.tags = @post.tags.where.not(id: @tag.id)
  else
    @post.tags << @tag
  end

  @post.save!
end

Protected Instance Methods

post() click to toggle source
# File lib/ecrire/app/controllers/admin/posts/tags_controller.rb, line 42
def post
  @post ||= Admin::Post.find(params[:post_id])
end
tag_params() click to toggle source
# File lib/ecrire/app/controllers/admin/posts/tags_controller.rb, line 46
def tag_params
  params.require(:tag).permit(:name)
end