Sha256: 4e8d37d0eb19f153b55cb0a74fee557aeba7c86e47318aeee1efcf4c007546c1

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

require_dependency "customer_vault/application_controller"

module CustomerVault
  class IndividualsController < ::CustomerVault::ApplicationController
    helper Dorsale::CommentsHelper

    before_action :set_individual, only: [:show, :edit, :update, :destroy]

    def show
      authorize! :read, @individual
    end

    def new
      authorize! :create, CustomerVault::Individual

      @individual ||= Individual.new
      @individual.build_address if @individual.address.nil?

      @tags ||= customer_vault_tag_list
    end

    def edit
      authorize! :update, @individual

      @individual.build_address if @individual.address.nil?

      @tags ||= customer_vault_tag_list
    end

    def create
      authorize! :create, CustomerVault::Individual

      @individual ||= Individual.new(individual_params)

      if @individual.save
        flash[:notice] = 'Individual was successfully created.'
        redirect_to @individual
      else
        render :new
      end
    end

    def update
      authorize! :update, @individual

      if @individual.update(individual_params)
        flash[:notice] = 'Individual was successfully updated.'
        redirect_to @individual
      else
        render :edit
      end
    end

    def destroy
      authorize! :delete, @individual

      if @individual.destroy
        flash[:notice] = 'Individual was successfully destroyed.'
      else
        flash[:alert] = 'Individual was NOT destroyed.'
      end

      redirect_to people_url
    end

    private

    def set_individual
      @individual = Individual.find(params[:id])
    end

    def permitted_params
      [
        :first_name, :last_name, {:tag_list => []}, :email, :title,
        :twitter, :www, :context, :phone, :fax, :mobile,
        :address_attributes => [:street, :street_bis, :zip, :city, :country]
      ]
    end

    def individual_params
      params.require(:individual).permit(permitted_params)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
customer_vault-1.2.10 app/controllers/customer_vault/individuals_controller.rb
customer_vault-1.2.9 app/controllers/customer_vault/individuals_controller.rb
customer_vault-1.2.8 app/controllers/customer_vault/individuals_controller.rb