Sha256: 822ee4a5dfb1fdd485032675dff27f802c4959677883ffa47bf1be648ebd3ee8

Contents?: true

Size: 1.72 KB

Versions: 8

Compression:

Stored size: 1.72 KB

Contents

module Rao
  module Component
    # Usage:
    #
    #     # app/models/gallery.rb
    #     class Picture < ActiveRecord::Base
    #       has_many :pictures, -> { order(position: :asc) }
    #       # ...
    #     end
    #
    #     # app/models/picture.rb
    #     class Picture < ActiveRecord::Base
    #       acts_as_list scope: :gallery
    #       # ...
    #     end
    #
    #     # app/galleries/index.html.haml
    #     = collection_table(collection: @pictures) do |table|
    #       = table.acts_as_list_actions scope: :gallery_id
    #
    # You will have to add a repositioning route to your resource:
    #
    #     # config/routes.rb:
    #     Rails.application.routes do
    #       resources :picture do
    #         post :reposition, on: :member
    #       end
    #       # ...
    #     end
    #
    # Additionally you will need a controller action to handle the reponsitioning.
    # Include Rao::ResourcesController::ActsAsListConcern from rao-resource_controller
    # if you don't want to implement it yourself:
    #
    #     # app/controllers/pictures_controller.rb
    #     class PicturesController < ApplicationController
    #       include Rao::ResourcesController::ActsAsListConcern
    #       # ...
    #     end
    #
    module CollectionTable::ActsAsListConcern
      extend ActiveSupport::Concern

      def acts_as_list_actions(options = {}, &block)
        options.reverse_merge!(render_as: :acts_as_list, title: t('.column_titles.acts_as_list'), scope: nil)

        scope = options.delete(:scope)
        scope = "#{scope}_id".intern if scope.is_a?(Symbol) && scope.to_s !~ /_id$/

        options.merge(scope: scope)

        column(:acts_as_list_actions, options, &block)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rao-component-0.0.10.pre app/concerns/rao/component/collection_table/acts_as_list_concern.rb
rao-component-0.0.9.pre app/concerns/rao/component/collection_table/acts_as_list_concern.rb
rao-component-0.0.8.pre app/concerns/rao/component/collection_table/acts_as_list_concern.rb
rao-component-0.0.7.pre app/concerns/rao/component/collection_table/acts_as_list_concern.rb
rao-component-0.0.6.pre app/concerns/rao/component/collection_table/acts_as_list_concern.rb
rao-component-0.0.5.pre app/concerns/rao/component/collection_table/acts_as_list_concern.rb
rao-component-0.0.4.pre app/concerns/rao/component/collection_table/acts_as_list_concern.rb
rao-component-0.0.3.pre app/concerns/rao/component/collection_table/acts_as_list_concern.rb