Class: Admin::Posts::TagsController
Instance Method Summary
collapse
#posts
#current_user, #signed_in?, #url
Instance Method Details
#create ⇒ Object
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
|
#index ⇒ Object
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
|
#toggle ⇒ Object
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
|