Sha256: 61137157df03f79f6c4614ce0c42d3c541c2b5ef95e7f4bb7ed7dd53d5742571
Contents?: true
Size: 1.37 KB
Versions: 6
Compression:
Stored size: 1.37 KB
Contents
require_dependency "customer_vault/application_controller" module CustomerVault class LinksController < ApplicationController before_action :load_linkable, only: [:new, :edit, :create, :update, :destroy] def new @link = Link.new end def edit @link = Link.find(params[:id]) end def create 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 redirect_to @person, notice: 'Link was successfully created.' else render action: 'new' end end def update @link = Link.find(params[:id]) if @link.update(link_params) redirect_to @person, notice: 'Link was successfully updated.' else render action: 'edit' end end def destroy Link.find(params[:id]).destroy redirect_to @person, notice: 'Individual was successfully destroyed.' 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 # Only allow a trusted parameter "white list" through. def link_params params.require(:link).permit(:bob, :title) end end end
Version data entries
6 entries across 6 versions & 1 rubygems