Class: RailsPulse::TagsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rails_pulse/tags_controller.rb

Constant Summary collapse

TAG_NAME_REGEX =

Tag validation rules

/\A[a-z0-9_-]+\z/i
MAX_TAG_LENGTH =
50

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_global_filters, #set_time_range

Methods included from PaginationConcern

#set_pagination_limit

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/rails_pulse/tags_controller.rb', line 9

def create
  tag = params[:tag]

  # Validate tag name
  error_message = validate_tag(tag)
  if error_message
    flash[:alert] = error_message
  elsif @taggable.add_tag(tag)
    flash[:notice] = "Tag added"
  else
    flash[:alert] = "Failed to add tag"
  end

  redirect_back(fallback_location: root_path)
end

#destroyObject



25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/rails_pulse/tags_controller.rb', line 25

def destroy
  tag = params[:tag]
  if @taggable.remove_tag(tag)
    flash[:notice] = "Tag removed"
  else
    flash[:alert] = "Failed to remove tag"
  end

  redirect_back(fallback_location: root_path)
end