Class: Back::TagsController

Inherits:
BackController
  • Object
show all
Defined in:
app/controllers/lato_blog/back/tags_controller.rb

Overview

Back::TagsController.

Instance Method Summary collapse

Instance Method Details

#createObject

This function creates a new tag.



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/lato_blog/back/tags_controller.rb', line 41

def create
  @tag = LatoBlog::Tag.new(new_tag_params)

  if !@tag.save
    flash[:danger] = @tag.errors.full_messages.to_sentence
    redirect_to lato_blog.new_tag_path
    return
  end

  flash[:success] = LANGUAGES[:lato_blog][:flashes][:tag_create_success]
  redirect_to lato_blog.tag_path(@tag.id)
end

#destroyObject

This function destroyes a tag.



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/lato_blog/back/tags_controller.rb', line 81

def destroy
  @tag = LatoBlog::Tag.find_by(id: params[:id])
  return unless check_tag_presence

  if !@tag.destroy
    flash[:danger] = @tag.tag_parent.errors.full_messages.to_sentence
    redirect_to lato_blog.edit_tag_path(@tag.id)
    return
  end

  flash[:success] = LANGUAGES[:lato_blog][:flashes][:tag_destroy_success]
  redirect_to lato_blog.categories_path(status: 'deleted')
end

#editObject

This function show the view to edit a tag.



55
56
57
58
59
60
61
62
63
# File 'app/controllers/lato_blog/back/tags_controller.rb', line 55

def edit
  core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:tags_edit])
  @tag = LatoBlog::Tag.find_by(id: params[:id])
  return unless check_tag_presence

  if @tag.meta_language != cookies[:lato_blog__current_language]
    set_current_language @tag.meta_language
  end
end

#indexObject

This function shows the list of possible tags.



13
14
15
16
17
18
# File 'app/controllers/lato_blog/back/tags_controller.rb', line 13

def index
  core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:tags])
  # find tags to show
  @tags = LatoBlog::Tag.where(meta_language: cookies[:lato_blog__current_language]).order('title ASC')
  @widget_index_tags = core__widgets_index(@tags, search: 'title', pagination: 10)
end

#newObject

This function shows the view to create a new tag.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/lato_blog/back/tags_controller.rb', line 27

def new
  core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:tags_new])
  @tag = LatoBlog::Tag.new

  if params[:language]
    set_current_language params[:language]
  end

  if params[:parent]
    @tag_parent = LatoBlog::TagParent.find_by(id: params[:parent])
  end
end

#showObject

This function shows a single tag. It create a redirect to the edit path.



21
22
23
24
# File 'app/controllers/lato_blog/back/tags_controller.rb', line 21

def show
  # use edit as default post show page
  redirect_to lato_blog.edit_tag_path(params[:id])
end

#updateObject

This function updates a tag.



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/lato_blog/back/tags_controller.rb', line 66

def update
  @tag = LatoBlog::Tag.find_by(id: params[:id])
  return unless check_tag_presence

  if !@tag.update(edit_tag_params)
    flash[:danger] = @tag.errors.full_messages.to_sentence
    redirect_to lato_blog.edit_tag_path(@tag.id)
    return
  end

  flash[:success] = LANGUAGES[:lato_blog][:flashes][:tag_update_success]
  redirect_to lato_blog.tag_path(@tag.id)
end