Sha256: 7a41ed01c88d291ee3b2c443f8464d52ea6b59597e636b0eed08ccd49d533e9c

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 KB

Contents

require_dependency "customer_vault/application_controller"

module CustomerVault
  class CorporationsController < ApplicationController
    helper Dorsale::CommentsHelper
    
    before_action :set_corporation, only: [:show, :edit, :update, :destroy]

    def show
      authorize! :read, @corporation
    end

    def new
      authorize! :create, CustomerVault::Corporation
      
      @corporation = Corporation.new
      @corporation.build_address
    end

    def edit
      authorize! :update, @corporation
      
      @corporation.build_address unless @corporation.address
    end

    def create
      authorize! :create, CustomerVault::Corporation
      
      @corporation = Corporation.new(corporation_params)

      if @corporation.save
        redirect_to @corporation, notice: 'Corporation was successfully created.'
      else
        render action: 'new'
      end
    end

    def update
      authorize! :update, @corporation
      
      if @corporation.update(corporation_params)
        redirect_to @corporation, notice: 'Corporation was successfully updated.'
      else
        render action: 'edit'
      end
    end

    def destroy
      authorize! :delete, @corporation
      
      @corporation.destroy
      redirect_to people_url, notice: 'Corporation was successfully destroyed.'
    end

    private
    
    def set_corporation
      @corporation = Corporation.find(params[:id])
    end

    def permitted_params
      [
        :name, :email, :phone, :fax,
        :address_attributes => [:street, :street_bis, :zip, :city, :country]
      ]
    end

    def corporation_params
      params.require(:corporation).permit(permitted_params)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
customer_vault-1.2.5 app/controllers/customer_vault/corporations_controller.rb
customer_vault-1.2.4 app/controllers/customer_vault/corporations_controller.rb
customer_vault-1.2.3 app/controllers/customer_vault/corporations_controller.rb
customer_vault-1.2.2 app/controllers/customer_vault/corporations_controller.rb
customer_vault-1.2.1 app/controllers/customer_vault/corporations_controller.rb