Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # frozen_string_literal: true
- class ConsentsController < ApplicationController
- layout :main_layout, only: %i[index show]
- before_action :set_branch, only: %i[index new create]
- before_action :set_consent, except: %i[index new create]
- def index
- @new_consent = Consent.new(branch: @branch)
- authorize(@new_consent)
- @consents = @branch.consents.page(params[:page])
- end
- def show
- authorize(@consent)
- end
- def new
- @consent = Consent.new(branch: @branch)
- authorize(@consent)
- end
- def create
- @consent = Consent.new(create_params)
- authorize(@consent)
- if @consent.save
- flash.notice = t('consents.create.flash.success')
- redirect_to consent_path(@consent)
- else
- render :new
- end
- end
- def edit
- authorize(@consent)
- end
- def update
- authorize(@consent)
- if @consent.update(update_params)
- flash.notice = t('consents.update.flash.success')
- redirect_to consent_path(@consent)
- else
- render :edit
- end
- end
- def destroy
- authorize(@consent)
- if @consent.destroy
- flash.notice = t('consents.destroy.flash.success')
- else
- flash.alert = t('consents.destroy.flash.alert')
- end
- redirect_to branch_consents_path(@branch)
- end
- private
- def set_branch
- @branch = policy_scope(Branch).find(params[:branch_id])
- end
- def set_consent
- @consent = policy_scope(Consent).find(params[:id])
- @branch = @consent.branch
- end
- def create_params
- params.require(:consent).permit(:name, :key, :based_on).merge!(branch: @branch)
- end
- def update_params
- params.require(:consent).permit(:name)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement