Sha256: c8f4bb4988f214573e96ce8a4a071bcece1671fdc2e518df9c4169cf8d538379

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

require_dependency "customer_vault/application_controller"

module CustomerVault
  class IndividualsController < ApplicationController
    before_action :set_individual, only: [:show, :edit, :update, :destroy]

    # GET /individuals/1
    def show
      authorize! :read, @individual
    end

    # GET /individuals/new
    def new
      authorize! :create, CustomerVault::Individual
      
      @individual = Individual.new
      @individual.build_address
    end

    # GET /individuals/1/edit
    def edit
      authorize! :update, @individual
      
      @individual.build_address unless @individual.address
    end

    # POST /individuals
    def create
      authorize! :create, CustomerVault::Individual
      
      @individual = Individual.new(individual_params)

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

    # PATCH/PUT /individuals/1
    def update
      authorize! :update, @individual
      
      if @individual.update(individual_params)
        redirect_to @individual, notice: 'Individual was successfully updated.'
      else
        render action: 'edit'
      end
    end

    # DELETE /individuals/1
    def destroy
      authorize! :delete, @individual
      
      @individual.destroy
      redirect_to people_url, notice: 'Individual was successfully destroyed.'
    end

    private
      # Use callbacks to share common setup or constraints between actions.
      def set_individual
        @individual = Individual.find(params[:id])
      end

      # Only allow a trusted parameter "white list" through.
      def individual_params
        params.require(:individual).permit(:first_name, :last_name, :email, :title, 
                                      :twitter, :www, :context, :phone, :fax, :mobile,
                                      :address_attributes => [:street, :street_bis, :zip, :city, :country])
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
customer_vault-1.2.0 app/controllers/customer_vault/individuals_controller.rb