foodsoft/app/controllers/admin/ordergroups_controller.rb

42 lines
1.5 KiB
Ruby
Raw Normal View History

class Admin::OrdergroupsController < Admin::BaseController
2011-06-10 01:36:04 +02:00
inherit_resources
2018-12-21 01:12:43 +01:00
def index
@ordergroups = Ordergroup.undeleted.sort_by_param(params['sort'])
2011-06-10 01:36:04 +02:00
2018-12-21 01:12:43 +01:00
if request.format.csv?
send_data OrdergroupsCsv.new(@ordergroups).to_csv, filename: 'ordergroups.csv',
type: 'text/csv'
2018-12-21 01:12:43 +01:00
end
2011-06-10 01:36:04 +02:00
# if somebody uses the search field:
@ordergroups = @ordergroups.where('name LIKE ?', "%#{params[:query]}%") if params[:query].present?
2011-06-10 01:36:04 +02:00
@ordergroups = @ordergroups.page(params[:page]).per(@per_page)
end
def update
sepa_account_holder_params = params[:ordergroup][:sepa_account_holder_attributes]
if sepa_account_holder_params&.[](:user_id).blank? || sepa_account_holder_params&.[](:group_id).blank?
if sepa_account_holder_params&.[](:id).present?
SepaAccountHolder.find(sepa_account_holder_params[:id]).destroy
end
params[:ordergroup].delete(:sepa_account_holder_attributes)
end
@ordergroup = Ordergroup.find(params[:id])
if @ordergroup.update(params[:ordergroup])
redirect_to admin_ordergroup_path(@ordergroup), notice: t('.notice')
else
redirect_to edit_admin_ordergroup_path(@ordergroup), alert: @ordergroup.errors.full_messages.join(', ')
end
end
def destroy
@ordergroup = Ordergroup.find(params[:id])
@ordergroup.mark_as_deleted
redirect_to admin_ordergroups_url, notice: t('.notice')
rescue StandardError => e
redirect_to admin_ordergroups_url, alert: t('.error')
end
end