require_dependency "customer_vault/application_controller" module CustomerVault class IndividualsController < ::CustomerVault::ApplicationController handles_sortable_columns helper Dorsale::CommentsHelper before_action :set_individual, only: [:show, :edit, :update, :destroy] def show authorize! :read, @individual @filters ||= Flyboy::SmallData::FilterForTasks.new(cookies) @tasks = @individual.tasks @tasks = @filters.apply(@tasks) 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