Class: AlchemyCrm::Admin::TagsController

Inherits:
Alchemy::Admin::BaseController
  • Object
show all
Includes:
I18nHelpers
Defined in:
app/controllers/alchemy_crm/admin/tags_controller.rb

Instance Method Summary collapse

Methods included from I18nHelpers

#alchemy_crm_t, #i18n_t, included, #translate_model_attribute

Instance Method Details

#createObject



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

def create
  @tag = ActsAsTaggableOn::Tag.create(params[:tag])
  render_errors_or_redirect @tag, admin_tags_path, alchemy_crm_t('New Tag Created')
end

#destroyObject



46
47
48
49
50
51
52
53
# File 'app/controllers/alchemy_crm/admin/tags_controller.rb', line 46

def destroy
  if request.delete?
    @tag.destroy
    flash[:notice] = alchemy_crm_t(:successfully_deleted_tag)
  end
  @redirect_url = admin_tags_path
  render :action => :redirect
end

#editObject



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

def edit
  @tags = ActsAsTaggableOn::Tag.order("name ASC").all - [@tag]
  render :layout => false
end

#indexObject



11
12
13
14
15
# File 'app/controllers/alchemy_crm/admin/tags_controller.rb', line 11

def index
  @tags = ActsAsTaggableOn::Tag.where(
    "name LIKE '%#{params[:query]}%'"
  ).page(params[:page] || 1).per(per_page_value_for_screen_size).order("name ASC")
end

#newObject



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

def new
  @tag = ActsAsTaggableOn::Tag.new
  render :layout => false
end

#updateObject



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

def update
  if params[:replace]
    @new_tag = ActsAsTaggableOn::Tag.find(params[:tag][:merge_to])
    Contact.replace_tag @tag, @new_tag
    operation_text = alchemy_crm_t('Replaced Tag %{old_tag} with %{new_tag}') % {:old_tag => @tag.name, :new_tag => @new_tag.name}
    @tag.destroy
  else
    @tag.update_attributes(params[:tag])
    @tag.save
    operation_text = alchemy_crm_t(:successfully_updated_tag)
  end
  render_errors_or_redirect @tag, admin_tags_path, operation_text
end