Class: Admin::Externals::GbPrimepay::MerchantsController
- Inherits:
-
BaseController
- Object
- BaseController
- Admin::Externals::GbPrimepay::MerchantsController
- Defined in:
- app/controllers/admin/externals/gb_primepay/merchants_controller.rb
Overview
typed: ignore
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 45 def create accepted_credit_cards = process_accepted_credit_cards(params[:externals_gb_primepay_merchant][:accepted_credit_cards]) @merchant = Externals::GbPrimepay::Merchant.new(permitted_param.merge(accepted_credit_cards: accepted_credit_cards)) if @merchant.valid? && @merchant.save update_restaurants(@merchant, params.require(:externals_gb_primepay_merchant).permit(restaurants_attributes: [:id, :_destroy])[:restaurants_attributes]&.values) redirect_to [:admin, @merchant], notice: 'Create successfully' else flash[:alert] = @merchant.errors..to_sentence render :edit end end |
#destroy ⇒ Object
64 65 66 67 68 69 70 |
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 64 def destroy if merchant.destroy redirect_to admin_externals_gb_primepay_merchants_path, notice: 'Deleted successfully' else redirect_to admin_externals_gb_primepay_merchants_path, alert: merchant.errors..to_sentence end end |
#edit ⇒ Object
15 16 17 |
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 15 def edit title: "Edit GB Primepay Merchants #{merchant.name}" end |
#index ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 6 def index title: 'GB Primepay Merchants Overview' @grid = ::Admin::Externals::GbPrimepay::MerchantsGrid.new(params[:branches_grid]) do |scope| scope.page(params[:page]).per(50) end etag = CityHash.hash32([self.class.to_s, @grid.assets.cache_key, params]) return unless stale?(etag: etag) end |
#new ⇒ Object
19 20 21 22 23 |
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 19 def new title: 'Add new GB Primepay Merchants' @merchant = Externals::GbPrimepay::Merchant.new @merchant.restaurants.build end |
#show ⇒ Object
60 61 62 |
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 60 def show title: "#{merchant.name} GB Primepay Merchant" end |
#update ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/admin/externals/gb_primepay/merchants_controller.rb', line 25 def update accepted_credit_cards = process_accepted_credit_cards(params[:externals_gb_primepay_merchant][:accepted_credit_cards]) if keys_changed? && !validate_users flash[:alert] = 'Unauthorized Access: You do not have permission to edit the Keys.' render :edit return end if @merchant.update(permitted_param.merge(accepted_credit_cards: accepted_credit_cards)) update_restaurants(@merchant, params.require(:externals_gb_primepay_merchant).permit(restaurants_attributes: [:id, :_destroy])[:restaurants_attributes]&.values) redirect_to [:admin, @merchant], notice: 'Updated successfully' else flash[:alert] = @merchant.errors..to_sentence render :edit end end |