Sha256: 5ba763b688f0285d89650ad52877f7c8b97f424d33b0d9c73ea315a3ed29c410

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

module ActsAsPublished
  module ActiveAdminHelper
    def acts_as_published_actions
      action_item :publish, :only => :show do
        if resource.published?
          link_to I18n.t('acts_as_published.actions.unpublish'), self.send(:"toggle_published_#{active_admin_config.namespace.name}_#{resource.class.model_name.to_s.underscore.gsub("/", "_")}_path", resource)
        else
          link_to I18n.t('acts_as_published.actions.publish'), self.send(:"toggle_published_#{active_admin_config.namespace.name}_#{resource.class.model_name.to_s.underscore.gsub("/", "_")}_path", resource)
        end
      end

      batch_action :toggle_published do |selection|
        active_admin_config.resource_class.find(selection).each do |item|
          item.toggle_published!
        end
        redirect_to :back
      end

      member_action :toggle_published do
        resource.toggle_published!
        if resource.published?
          redirect_to :back, :notice => I18n.t('acts_as_published.notices.published', :name => resource )
        else
          redirect_to :back, :notice => I18n.t('acts_as_published.notices.unpublished', :name => resource )
        end
      end
    end

    def acts_as_published_columns
      column :published do |resource|
        I18n.t(resource.published.to_s)
      end
    end

    def acts_as_published_rows
      row :published do |resource|
        I18n.t(resource.published.to_s)
      end
      row :published_at
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
acts_as_published-1.1.0 lib/acts_as_published/active_admin_helper.rb
acts_as_published-1.0.3 lib/acts_as_published/active_admin_helper.rb
acts_as_published-1.0.2 lib/acts_as_published/active_admin_helper.rb
acts_as_published-1.0.1 lib/acts_as_published/active_admin_helper.rb