Class: CamaleonCms::Admin::PostTagsController

Inherits:
CamaleonCms::AdminController show all
Includes:
CustomFieldsConcern
Defined in:
app/controllers/camaleon_cms/admin/post_tags_controller.rb

Instance Method Summary collapse

Methods inherited from CamaleonCms::AdminController

#ajax, #cama_get_i18n_frontend, #dashboard, #search

Instance Method Details

#createObject

render post tag create form



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/camaleon_cms/admin/post_tags_controller.rb', line 45

def create
  @post_tag = @post_type..new()
  args = { post_tag: @post_tag, post_type: @post_type }
  hooks_run('before_create_post_tag', args)
  if @post_tag.save
    @post_tag.set_options(params[:meta]) if params[:meta].present?
    @post_tag.set_field_values(cama_permitted_field_options('PostType_PostTag'))
    hooks_run('after_create_post_tag', args)
    flash[:notice] = t('camaleon_cms.admin.post_type.message.created')
    redirect_to action: :index
  else
    render 'edit'
  end
end

#destroyObject

destroy a post tag



61
62
63
64
65
66
# File 'app/controllers/camaleon_cms/admin/post_tags_controller.rb', line 61

def destroy
  args = { post_tag: @post_tag, post_type: @post_type }
  hooks_run('before_destroy_post_tag', args)
  flash[:notice] = t('camaleon_cms.admin.post_type.message.deleted') if @post_tag.destroy
  redirect_to action: :index
end

#editObject

render post tag edit form



25
26
27
# File 'app/controllers/camaleon_cms/admin/post_tags_controller.rb', line 25

def edit
  add_breadcrumb t('camaleon_cms.admin.button.edit')
end

#indexObject



11
12
13
14
15
16
# File 'app/controllers/camaleon_cms/admin/post_tags_controller.rb', line 11

def index
  @post_tags = @post_type.
  args = { post_type: @post_type }
  hooks_run('before_list_post_tags', args)
  @post_tags = @post_tags.paginate(page: params[:page], per_page: current_site.admin_per_page)
end

#listObject

render a json of post tags of a post type



69
70
71
72
# File 'app/controllers/camaleon_cms/admin/post_tags_controller.rb', line 69

def list
  @post_tags = @post_type..pluck('name')
  render json: @post_tags
end

#showObject

render post tag view



19
20
21
22
# File 'app/controllers/camaleon_cms/admin/post_tags_controller.rb', line 19

def show
  args = { post_tag: @post_tag, post_type: @post_type }
  hooks_run('before_show_post_tag', args)
end

#updateObject

save changes of a post tag



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/camaleon_cms/admin/post_tags_controller.rb', line 30

def update
  args = { post_tag: @post_tag, post_type: @post_type }
  hooks_run('before_update_post_tag', args)
  if @post_tag.update()
    @post_tag.set_options(params[:meta]) if params[:meta].present?
    @post_tag.set_field_values(cama_permitted_field_options('PostType_PostTag'))
    hooks_run('after_update_post_tag', args)
    flash[:notice] = t('camaleon_cms.admin.post_type.message.updated')
    redirect_to action: :index
  else
    render edit
  end
end