Sha256: 9d9f383dd85123938d2c34b76f6ace2d339a5edee29cad8cf7c0232ca75b957d

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

module Naf
  class AffinitiesController < Naf::ApplicationController

    before_filter :set_cols_and_attributes

    def index
      @affinities = Naf::Affinity.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

5 entries across 5 versions & 1 rubygems

Version Path
naf-1.1.4 app/controllers/naf/affinities_controller.rb
naf-1.1.3 app/controllers/naf/affinities_controller.rb
naf-1.1.2 app/controllers/naf/affinities_controller.rb
naf-1.1.1 app/controllers/naf/affinities_controller.rb
naf-1.1.0 app/controllers/naf/affinities_controller.rb