Sha256: b388287ec8eafb7f2c7c222cc2371eff4a85f1deb4e214fd3b9e1bf5627e5e67

Contents?: true

Size: 1.45 KB

Versions: 38

Compression:

Stored size: 1.45 KB

Contents

module Pulitzer
  class TagsController < ApplicationController
    before_filter :get_tag, only: [:edit, :update, :destroy]

    rescue_from ActiveRecord::RecordNotFound, with: :render_not_found

    def index
      @root_tags = Tag.root
      @flat_tags = Tag.flat
      render partial: 'index'
    end

    def new
      @tag = Tag.new(tag_params)
      render partial: new_template(@tag)
    end

    def edit
      render partial: 'form', locals: { tag: @tag }
    end

    def show
      @tag = Tag.find(params[:id])
      render partial: 'show', locals: { tag: @tag }
    end

    def create
      @tag = Tag.new(tag_params)
      if @tag.save
        render partial: 'show_wrapper', locals: { tag: @tag }
      else
        render partial: new_template(@tag), locals: { tag: @tag }, status: 409
      end
    end

    def update
      if @tag.update_attributes(tag_params)
        render partial: 'show', locals: { tag: @tag }
      else
        render partial: 'form', locals: { tag: @tag }, status: 409
      end
    end

    def destroy
      @tag.destroy
      render nothing: true
    end

    protected

    def new_template(tag)
      tag.hierarchical? ? 'new_hierarchical' : 'new_flat'
    end

    def render_not_found(e)
      Rails.logger.warn("Rendering 404 because #{e.inspect}")
      render nothing: true, status: :not_found
    end

    def tag_params
      params[:tag].permit!
    end

    def get_tag
      @tag = Tag.find(params[:id])
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
pulitzer-0.12.5 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.12.4 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.12.3 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.12.2 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.12.1 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.12.0 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.11.3 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.11.2 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.11.1 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.11.0 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.10.3 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.10.2 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.10.1 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.10.0 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.5.14 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.5.13 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.5.11 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.5.10 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.5.9 app/controllers/pulitzer/tags_controller.rb
pulitzer-0.5.8 app/controllers/pulitzer/tags_controller.rb