Sha256: bc603094027c6ac531cc1112532e58b6a7a998f22ddb2c665f4c31b92a75178e

Contents?: true

Size: 1.43 KB

Versions: 18

Compression:

Stored size: 1.43 KB

Contents

module Naf
  class AffinitiesController < Naf::ApplicationController

    before_filter :set_cols_and_attributes

    def index
      @affinities = ::Naf::Affinity.includes(:affinity_classification).all
    end

    def show
      @affinity = Naf::Affinity.find(params[:id])
    end

    def destroy
      @affinity = Naf::Affinity.find(params[:id])
      @affinity.destroy
      flash[:notice] = "Affinity '#{@affinity.affinity_name}' was successfully deleted."
      redirect_to(action: "index")
    end

    def new
      @affinity = Naf::Affinity.new
    end

    def create
      @affinity = Naf::Affinity.new(params[:affinity])

      if message = @affinity.validate_affinity_name
        flash[:error] = message
        redirect_to :back
        return
      end

      if @affinity.save
        redirect_to(@affinity, notice: "Affinity '#{@affinity.affinity_name}' was successfully created.")
      else
        render action: "new"
      end
    end

    def edit
      @affinity = Naf::Affinity.find(params[:id])
    end

    def update
      @affinity = Naf::Affinity.find(params[:id])
      if @affinity.update_attributes(params[:affinity])
        redirect_to(@affinity, notice: "Affinity '#{@affinity.affinity_name}' was successfully updated.")
      else
        render action: "edit"
      end
    end

    private

    def set_cols_and_attributes
      @cols = [:id, :affinity_classification_name, :affinity_name, :affinity_note]
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
naf-2.1.13 app/controllers/naf/affinities_controller.rb
naf-2.1.12 app/controllers/naf/affinities_controller.rb
naf-2.1.11 app/controllers/naf/affinities_controller.rb
naf-2.1.10 app/controllers/naf/affinities_controller.rb
naf-2.1.9 app/controllers/naf/affinities_controller.rb
naf-2.1.8 app/controllers/naf/affinities_controller.rb
naf-2.1.6 app/controllers/naf/affinities_controller.rb
naf-2.1.5 app/controllers/naf/affinities_controller.rb
naf-2.1.4 app/controllers/naf/affinities_controller.rb
naf-2.1.3 app/controllers/naf/affinities_controller.rb
naf-2.1.2 app/controllers/naf/affinities_controller.rb
naf-2.1.1 app/controllers/naf/affinities_controller.rb
naf-2.1.0 app/controllers/naf/affinities_controller.rb
naf-2.0.4 app/controllers/naf/affinities_controller.rb
naf-2.0.3 app/controllers/naf/affinities_controller.rb
naf-2.0.2 app/controllers/naf/affinities_controller.rb
naf-2.0.1 app/controllers/naf/affinities_controller.rb
naf-2.0.0 app/controllers/naf/affinities_controller.rb