Sha256: 9656e0003a417b567df3e09bcb5998b010a7cb47e62c4172604432e0b10f352f

Contents?: true

Size: 1.49 KB

Versions: 10

Compression:

Stored size: 1.49 KB

Contents

require_dependency "commenteux/application_controller"

module Commenteux
  class NotesController < ApplicationController

    def comments_params
      comments_permit_fields = [:title, :comment, :user_id]
      params.require(:comments).permit(
          comments_permit_fields)
    end

    def index
      resource = fetch_resource
      @comments = resource.comments.all
      @parent_div = params[:parent_div]

      if request.xhr?
        render :layout => false
      end

    end

    def fetch_resource
      @resource = params[:resource]
      @class_name = classify_namespace(params[:resource])
      @resourceKlass = eval(@class_name)
      @resource_id = params[:resource_id]
      @resourceKlass.find(@resource_id)
    end

    def classify_namespace(const)
      const = const.classify
      if const.include?('::')
        new_const = ''
        splitted = const.split('::')
        for str in splitted do
          new_const = new_const + str.classify + '::'
        end
        const = new_const[0..(new_const.length - 3)]
      end
      const
    end

    def new
      resource = fetch_resource
      @comments = resource.comments.new
      @parent_div = params[:parent_div]

      if request.xhr?
        render :layout => false
      end

    end

    def create
      resource = fetch_resource
      resource.comments.create(comments_params)
      @parent_div = params[:parent_div]
      redirect_to "/commenteux/#{@resource.downcase}/#{@resource_id}?parent_div=" + @parent_div
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
commenteux-1.1.2 app/controllers/commenteux/notes_controller.rb
commenteux-1.1.1 app/controllers/commenteux/notes_controller.rb
commenteux-1.1.0 app/controllers/commenteux/notes_controller.rb
commenteux-1.0.6 app/controllers/commenteux/notes_controller.rb
commenteux-1.0.5 app/controllers/commenteux/notes_controller.rb
commenteux-1.0.4 app/controllers/commenteux/notes_controller.rb
commenteux-1.0.3 app/controllers/commenteux/notes_controller.rb
commenteux-1.0.2 app/controllers/commenteux/notes_controller.rb
commenteux-1.0.1 app/controllers/commenteux/notes_controller.rb
commenteux-1.0.0 app/controllers/commenteux/notes_controller.rb