app/controllers/comable/admin/application_controller.rb in comable_backend-0.3.4 vs app/controllers/comable/admin/application_controller.rb in comable_backend-0.4.0
- old
+ new
@@ -7,32 +7,52 @@
helper Sprockets::Helpers::RailsHelper if Rails::VERSION::MAJOR == 3
layout 'comable/admin/application'
def current_ability
- Comable::Ability.new(current_customer)
+ Comable::Ability.new(current_comable_user)
end
+ def respond_to_export_with(records)
+ respond_to do |format|
+ format.csv do
+ render csv: records, filename: filename
+ end
+
+ format.xlsx do
+ render xlsx: 'export', filename: filename, locals: { records: records }, template: 'comable/admin/shared/export', layout: false
+ end
+ end
+ end
+
private
rescue_from CanCan::AccessDenied, with: :unauthorized
def unauthorized
- if current_customer.signed_in?
+ if current_comable_user.signed_in?
flash[:alert] = Comable.t('admin.access_denied')
redirect_to after_access_denied_path
else
store_location
- redirect_to comable.new_admin_customer_session_path
+ redirect_to comable.new_admin_user_session_path
end
end
def after_access_denied_path
- if current_customer.customer?
+ if current_comable_user.user?
comable.root_path
else
comable.admin_root_path
end
+ end
+
+ def filename
+ "#{timestamp}_#{controller_name}"
+ end
+
+ def timestamp
+ Time.now.strftime('%Y%m%d%H%M%S')
end
end
end
end