Class: Wco::TagsController
Instance Method Summary
collapse
#home, #tinymce
#my_truthy?, #obfuscate, #pexels_search_path, #pp_amount, #pp_currency, #pp_date, #pp_datetime, #pp_money, #pp_percent, #pp_time, #pretty_date
Instance Method Details
#add_to ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'app/controllers/wco/tags_controller.rb', line 53
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
|
#add_to_many ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/controllers/wco/tags_controller.rb', line 64
def add_to_many
@tag = Wco::Tag.find params[:id]
resources = params[:resource].constantize.find params[:resource_ids]
authorize! :update, @tag
flags = []
resources.each do |resource|
resource.tags.push @tag
flags.push resource.save
end
flash_notice flags
end
|
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|
#edit ⇒ Object
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
|
#index ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/wco/tags_controller.rb', line 33
def index
authorize! :index, Wco::Tag
@tags = Wco::Tag.all
tags = Wco::Tag.all.to_a.group_by(&:parent_id)
build_tree = lambda do |parent_id|
(tags[parent_id] || []).sort_by { |tag| tag.slug.downcase }.map do |tag|
{ tag: tag, sons: build_tree.call(tag.id) }
end
end
@tree = build_tree.call(nil)
@template = params[:template] || 'index_tree'
end
|
#new ⇒ Object
49
50
51
|
# File 'app/controllers/wco/tags_controller.rb', line 49
def new
authorize! :new, Wco::Tag
end
|
#remove_from ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'app/controllers/wco/tags_controller.rb', line 78
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
|
#remove_from_many ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'app/controllers/wco/tags_controller.rb', line 89
def remove_from_many
@tag = Wco::Tag.find params[:id]
resources = params[:resource].constantize.find params[:resource_ids]
authorize! :update, @tag
flags = []
resources.each do |resource|
resource.tags.delete @tag
flags.push resource.save
end
flash_notice flags
end
|
#show ⇒ Object
103
104
105
106
107
108
109
110
111
|
# File 'app/controllers/wco/tags_controller.rb', line 103
def show
@tag = Wco::Tag.find params[:id]
authorize! :show, @tag
@galleries = @tag.galleries.page( params[:galleries_page] ).per( current_profile.per_page )
@leads = @tag.leads.page( params[::Wco::Lead::PAGE_PARAM_NAME] ).per( current_profile.per_page )
@leadsets = @tag.leadsets.page( params[::Wco::Leadset::PAGE_PARAM_NAME] ).per( current_profile.per_page )
@reports = @tag.reports.page( params[:reports_page] ).per( current_profile.per_page )
end
|
#update ⇒ Object
113
114
115
116
117
118
119
120
121
122
|
# File 'app/controllers/wco/tags_controller.rb', line 113
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
|