Class: Wco::TagsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#home, #tinymce

Methods included from ApplicationHelper

#my_truthy?, #obfuscate, #pp_amount, #pp_currency, #pp_date, #pp_datetime, #pp_money, #pp_percent, #pp_time, #pretty_date

Instance Method Details

#add_toObject



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

def add_to
  @tag = Wco::Tag.find params[:id]
  resource = params[:resource].constantize.find params[:resource_id]
  authorize! :update, @tag

  resource.tags.push @tag
  flag = resource.save
  flash_notice 'maybe?'
  redirect_to request.referrer
end

#createObject



6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/wco/tags_controller.rb', line 6

def create
  @tag = Wco::Tag.new params[:tag].permit!
  authorize! :create, @tag
  if @tag.save
    flash_notice "created tag"
  else
    flash_alert "Cannot create tag: #{@tag.errors.messages}"
  end
  redirect_to action: 'index'
end

#destroyObject



17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/wco/tags_controller.rb', line 17

def destroy
  @tag = Wco::Tag.find params[:id]
  authorize! :destroy, @tag
  if @tag.destroy
    flash_notice 'ok'
  else
    flash_alert 'No luck.'
  end
  redirect_to action: 'index'
end

#editObject



28
29
30
31
# File 'app/controllers/wco/tags_controller.rb', line 28

def edit
  @tag = Wco::Tag.find params[:id]
  authorize! :edit, @tag
end

#indexObject



33
34
35
36
# File 'app/controllers/wco/tags_controller.rb', line 33

def index
  authorize! :index, Wco::Tag
  @tags = Wco::Tag.all
end

#newObject



38
39
40
# File 'app/controllers/wco/tags_controller.rb', line 38

def new
  authorize! :new, Wco::Tag
end

#remove_fromObject



53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/wco/tags_controller.rb', line 53

def remove_from
  @tag = Wco::Tag.find params[:id]
  resource = params[:resource].constantize.find params[:resource_id]
  authorize! :update, @tag

  resource.tags.delete @tag
  flag = resource.save
  flash_notice 'maybe?'
  redirect_to request.referrer
end

#showObject



64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/wco/tags_controller.rb', line 64

def show
  @tag = Wco::Tag.find params[:id]
  authorize! :show, @tag

  @galleries = @tag.galleries(
    ).page( params[:galleries_page] ).per( current_profile.per_page )

  @reports = @tag.reports(
    ).page( params[:reports_page] ).per( current_profile.per_page )

end

#updateObject



76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/wco/tags_controller.rb', line 76

def update
  @tag = Wco::Tag.find params[:id]
  authorize! :update, @tag
  if @tag.update params[:tag].permit!
    flash_notice "updated tag"
  else
    flash_alert "Cannot update tag: #{@tag.errors.messages}"
  end
  redirect_to action: 'index'
end