Sha256: 634cd1b9ea0127336e84b11c86de3d6c4f43efb80007b60844a6bb2034b5a8e4

Contents?: true

Size: 1.59 KB

Versions: 6

Compression:

Stored size: 1.59 KB

Contents

ActiveAdmin.register Product do
  menu :priority => 3, label: 'Products'

  permit_params :category_id, :active, :name, :slug, :price, :description,
    images_attributes: [:id, :_destroy, :image]

  form(:html => { :multipart => true }) do |f|
    f.inputs 'Product' do
      f.input :category, :as => :select,
        :collection => Category.all.collect { |c| ["#{'  -- ' * c.depth}#{c.name}", c.id ] }
      f.input :active
      f.input :name
      f.input :price
      f.input :description, :as => :ckeditor
    end

    f.inputs 'Additional images' do
      f.has_many :images do |image_form|
        image_form.input :image, :as  => :file,
          :hint => image_tag(image_form.object.image.admin_thumb.url)
          image_form.input :_destroy, :as => :boolean, :label => 'delete?'
      end
    end

    f.actions
  end

  index do
    column :name
    column :image do |product|
      if (image = product.main_image).present?
        link_to edit_admin_product_path(product) do
          image_tag(product.main_image.image.admin_thumb.url)
        end
      else
        status_tag('Image not uplaoded')
      end
    end
    column :slug
    column :category
    column :active do |product|
      product.active? ? status_tag("Active", :ok) : status_tag("Disabled")
    end
    column :price

    actions
  end

  filter :active
  filter :category
  filter :name
  filter :price

  # Preload association fore remove (n+1) query
  def scoped_collection
    resource_class.includes(:category, :images)
  end

  controller do
    def find_resource
      scoped_collection.friendly.find(params[:id])
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
power_shop-0.2.4 lib/generators/power_shop/install/templates/active_admin/product.rb.erb
power_shop-0.2.3 lib/generators/power_shop/install/templates/active_admin/product.rb.erb
power_shop-0.2.2 lib/generators/power_shop/install/templates/active_admin/product.rb.erb
power_shop-0.2.1 lib/generators/power_shop/install/templates/active_admin/product.rb.erb
power_shop-0.2.0 lib/generators/power_shop/install/templates/active_admin/product.rb.erb
power_shop-0.1.1 lib/generators/power_shop/install/templates/active_admin/product.rb.erb