require_dependency "customer_vault/application_controller" module CustomerVault class CorporationsController < ::CustomerVault::ApplicationController handles_sortable_columns helper Dorsale::CommentsHelper before_action :set_corporation, only: [:show, :edit, :update, :destroy] def show authorize! :read, @corporation @filters ||= Flyboy::SmallData::FilterForTasks.new(cookies) @tasks = @corporation.tasks @tasks = @filters.apply(@tasks) end def new authorize! :create, CustomerVault::Corporation @corporation ||= Corporation.new @corporation.build_address if @corporation.address.nil? @tags ||= customer_vault_tag_list end def edit authorize! :update, @corporation @corporation.build_address if @corporation.address.nil? @tags ||= customer_vault_tag_list end def create authorize! :create, CustomerVault::Corporation @corporation ||= Corporation.new(corporation_params) if @corporation.save flash[:notice] = 'Corporation was successfully created.' redirect_to @corporation else render :new end end def update authorize! :update, @corporation if @corporation.update(corporation_params) flash[:notice] = 'Corporation was successfully updated.' redirect_to @corporation else render :edit end end def destroy authorize! :delete, @corporation if @corporation.destroy flash[:notice] = 'Corporation was successfully destroyed.' else flash[:alert] = 'Corporation was NOT destroyed.' end redirect_to people_url end private def set_corporation @corporation = Corporation.find(params[:id]) end def permitted_params [ :name, {:tag_list => []}, :email, :www, :phone, :fax, :capital, :immatriculation_number_1, :immatriculation_number_2, :legal_form, :address_attributes => [:street, :street_bis, :zip, :city, :country] ] end def corporation_params params.require(:corporation).permit(permitted_params) end end end