Sha256: 221583249606786dd60f0f4ebaf14a6894c007c032f45c7263ea0653ae1a1ada

Contents?: true

Size: 1.51 KB

Versions: 18

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module Cmor::Seo
  class ItemsController < Cmor::Core::Backend::ResourcesController::Base
    include Rao::ResourcesController::ActsAsPublishedConcern

    def self.resource_class
      Cmor::Seo::Item
    end

    module AutocompleteConcern
      extend ActiveSupport::Concern

      def autocomplete_resource
        resource_class_name = params[:resource_class_name]
        term                = params[:term] || ""

        autocomplete_options = autocomplete_options_for(resource_class_name)

        if autocomplete_options.present?
          resources = autocomplete_options[:scope].call(term).all

          results = resources.collect do |resource|
            { id: resource.send(autocomplete_options[:id_method]), text: resource.send(autocomplete_options[:text_method]) }
          end
        else
          results = []
        end

        respond_to do |format|
          format.json do
            render json: { results: results }
          end
        end
      end

      private
        def autocomplete_options_for(resource_class_name)
          Cmor::Seo::Configuration.resources_autocomplete_options[resource_class_name][:autocomplete_options]
        end
    end

    include AutocompleteConcern

    private
      def load_collection_scope
        super.eager_load(:meta_tags)
      end

      def permitted_params
        params.require(:item).permit(:resource_type, :resource_id, :path, :published, meta_tags_attributes: [:id, :name, :content, :published, :_destroy])
      end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
cmor_seo-0.0.60.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.59.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.58.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.57.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.56.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.55.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.54.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.53.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.52.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.51.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.50.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.49.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.48.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.45.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.44.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.43.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.42.pre app/controllers/cmor/seo/items_controller.rb
cmor_seo-0.0.41.pre app/controllers/cmor/seo/items_controller.rb