Class: Admin::Posts::TagsController

Inherits:
ApplicationController show all
Defined in:
lib/ecrire/app/controllers/admin/posts/tags_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#posts

Methods inherited from ApplicationController

#current_user, #signed_in?, #url

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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

#indexObject



6
7
8
9
10
11
# 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

#toggleObject



29
30
31
32
33
34
35
36
37
38
# 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