Class: Admin::BaseController
Instance Method Summary
collapse
Instance Method Details
#allow_batch_action?(batch_action) ⇒ Boolean
90
91
92
|
# File 'app/controllers/admin/base_controller.rb', line 90
def allow_batch_action?(batch_action)
resource_class.batch_actions.include?(batch_action)
end
|
#apply_batch_action(item, batch_action) ⇒ Object
86
87
88
|
# File 'app/controllers/admin/base_controller.rb', line 86
def apply_batch_action(item, batch_action)
item.send(batch_action)
end
|
74
75
76
77
78
79
80
81
82
83
84
|
# File 'app/controllers/admin/base_controller.rb', line 74
def batch
raise 'No ids specified for batch action' unless params[:ids].present?
batch_action = params[:batch_action].to_sym
if allow_batch_action?(batch_action) && collection.all?{|item| can?(batch_action, item) }
count = collection.inject(0) { |c, item| apply_batch_action(item, batch_action) ? c + 1 : c }
flash[:success] = I18n.t('admin.batch_actions.status', count: count, action: I18n.t("admin.actions.batch_#{batch_action}.title"))
else
raise CanCan::AccessDenied
end
redirect_to :back
end
|
41
42
43
44
45
46
47
|
# File 'app/controllers/admin/base_controller.rb', line 41
def create
create! do |success, failure|
success.html { redirect_to redirect_to_on_success }
success.js { render layout: false }
failure.js { render :new, layout: false }
end
end
|
58
59
60
|
# File 'app/controllers/admin/base_controller.rb', line 58
def destroy
destroy! { redirect_to_on_success }
end
|
62
63
64
65
66
|
# File 'app/controllers/admin/base_controller.rb', line 62
def edit
edit! do |format|
format.js { render layout: false }
end
end
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/controllers/admin/base_controller.rb', line 25
def index
super do |format|
format.js { render layout: false }
format.csv do
doc = AbAdmin::Utils::CsvDocument.new(collection, export_options)
send_data(doc.render, filename: doc.filename, type: Mime::CSV, disposition: 'attachment')
end
if defined?(Mime::XLSX)
format.xls do
doc = AbAdmin::Utils::XlsDocument.new(collection, export_options)
send_data(doc.render, filename: doc.filename, type: Mime::XLSX, disposition: 'attachment')
end
end
end
end
|
68
69
70
71
72
|
# File 'app/controllers/admin/base_controller.rb', line 68
def new
new! do |format|
format.js { render layout: false }
end
end
|
49
50
51
52
53
54
55
56
|
# File 'app/controllers/admin/base_controller.rb', line 49
def update
update! do |success, failure|
success.html { redirect_to redirect_to_on_success }
failure.html { render :edit }
success.js { render layout: false }
failure.js { render :edit, layout: false }
end
end
|