Garbar
8/13/2015 - 1:10 PM

ActiveAdmin custom action

ActiveAdmin custom action

%h2 Import

= form_tag(import_admin_product_path(@product), method: "post", multipart: true) do |f|

  Field1:
  = text_field_tag 'field1'
  %br

  %input(type="file" name="file" placeholder="File")
  %br

  = submit_tag "Upload"

%br
ActiveAdmin.register Product do
  ...

  member_action :showimport, :method=>:get do

  end

  member_action :import, :method=>:post do
    
  end


  controller do

    def showimport
      @product = Product.find(params[:id])
      
    end

    def import
    
      # renders view 'app/views/admin/products/showimport.html.haml'
    end
    

  end


end
ActiveAdmin.register Product do

  index :as => :table do
    column :title
    column :price
    
    actions

  end

end
  controller do
    ...
    
    def dosmth
      # do some stuff

      
      # shows view '/admin/products/dosmth.html.haml'
      #render 'dosmth' 
    end
  end
  action_item do
    link_to "Do smth", dosmth_admin_products_path
  end


  collection_action :dosmth, :method => :get do
    
  end
  controller do
    ..
    def import
      @product = Product.find(params[:id])

      # access uploaded file - params[:file]

      # do the job


      # redirect
      redirect_to showimport_admin_product_path(@product), :notice=>'Imported'
    end
  end