Class: Alchemy::Admin::TagsController

Inherits:
ResourcesController show all
Defined in:
app/controllers/alchemy/admin/tags_controller.rb

Constant Summary

Constants inherited from ResourcesController

ResourcesController::COMMON_SEARCH_FILTER_EXCLUDES

Instance Method Summary collapse

Methods inherited from ResourcesController

#resource_filters, #resource_filters_for_select, #resource_handler, #resource_has_deprecated_filters, #resource_has_filters, #show

Methods included from ResourcesHelper

#contains_relations?, #edit_resource_path, #new_resource_path, #render_attribute, #render_resources, #resource_attribute_field_options, #resource_has_tags, #resource_instance_variable, #resource_model, #resource_name, #resource_path, #resource_relations_names, #resource_scope, #resource_url_proxy, #resource_window_size, #resources_instance_variable, #resources_path, #sortable_resource_header_column

Methods inherited from BaseController

#leave

Methods included from Modules

included, #module_definition_for, register_module

Methods included from Alchemy::AbilityHelper

#current_ability

Methods included from ConfigurationMethods

#configuration, #multi_language?, #multi_site?, #prefix_locale?

Instance Method Details

#autocompleteObject



52
53
54
55
# File 'app/controllers/alchemy/admin/tags_controller.rb', line 52

def autocomplete
  items = tags_from_term(params[:term])
  render json: json_for_autocomplete(items, :name).to_json
end

#createObject



22
23
24
25
# File 'app/controllers/alchemy/admin/tags_controller.rb', line 22

def create
  @tag = Tag.create(tag_params)
  render_errors_or_redirect @tag, admin_tags_path, Alchemy.t("New Tag Created")
end

#destroyObject



44
45
46
47
48
49
50
# File 'app/controllers/alchemy/admin/tags_controller.rb', line 44

def destroy
  if request.delete?
    @tag.destroy
    flash[:notice] = Alchemy.t(:successfully_deleted_tag)
  end
  do_redirect_to admin_tags_path
end

#editObject



27
28
29
# File 'app/controllers/alchemy/admin/tags_controller.rb', line 27

def edit
  @tags = Tag.order("name ASC").to_a - [@tag]
end

#indexObject



8
9
10
11
12
13
14
15
16
# File 'app/controllers/alchemy/admin/tags_controller.rb', line 8

def index
  @query = Tag.ransack(search_filter_params[:q])
  @query.sorts = default_sort_order if @query.sorts.empty?
  @tags = @query
    .result
    .page(params[:page] || 1)
    .per(items_per_page)
    .order("name ASC")
end

#newObject



18
19
20
# File 'app/controllers/alchemy/admin/tags_controller.rb', line 18

def new
  @tag = Tag.new
end

#updateObject



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

def update
  if tag_params[:merge_to]
    @new_tag = Tag.find(tag_params[:merge_to])
    Tag.replace(@tag, @new_tag)
    operation_text = Alchemy.t("Replaced Tag") % {old_tag: @tag.name, new_tag: @new_tag.name}
    @tag.destroy
  else
    @tag.update(tag_params)
    operation_text = Alchemy.t(:successfully_updated_tag)
  end
  render_errors_or_redirect @tag, admin_tags_path, operation_text
end