Sha256: f3a2a1694e0445334884cdc7afb7025a74278abc4c2d91845f06b8a4dc09df3d
Contents?: true
Size: 1.78 KB
Versions: 6
Compression:
Stored size: 1.78 KB
Contents
require_dependency "customer_vault/application_controller" module CustomerVault class LinksController < ::CustomerVault::ApplicationController before_action :load_linkable, only: [:new, :edit, :create, :update, :destroy] def new authorize! :update, @person @link ||= Link.new @people ||= Person.list end def edit authorize! :update, @person @link = Link.find(params[:id]) end def create authorize! :update, @person params = link_params bob = params[:bob].split("-") @link ||= Link.new(title: params[:title], alice_id: @person.id, alice_type: @person.class.to_s, bob_id: bob[1], bob_type: bob[0]) if @link.save flash[:notice] = 'Link was successfully created.' redirect_to url_for(@person) + "#links" else render :new end end def update authorize! :update, @person @link = Link.find(params[:id]) if @link.update(link_params) flash[:notice] = 'Link was successfully updated.' redirect_to url_for(@person) + "#links" else render :edit end end def destroy authorize! :update, @person @link = Link.find(params[:id]) if @link.destroy flash[:notice] = 'Individual was successfully destroyed.' else flash[:alert] = 'Individual was NOT destroyed.' end redirect_to url_for(@person) + "#links" end private def load_linkable klass = [Individual, Corporation].detect { |c| params["#{c.name.demodulize.underscore}_id"] } @person = klass.find(params["#{klass.name.demodulize.underscore}_id"]) end def permitted_params [:bob, :title] end def link_params params.require(:link).permit(permitted_params) end end end
Version data entries
6 entries across 6 versions & 1 rubygems