Skip to content

Instantly share code, notes, and snippets.

@mike1011
Forked from maxivak/00.md
Created September 9, 2017 19:52
Show Gist options
  • Save mike1011/179d605b218f0345507728baa445461b to your computer and use it in GitHub Desktop.
Save mike1011/179d605b218f0345507728baa445461b to your computer and use it in GitHub Desktop.
ActiveAdmin custom action

ActiveAdmin custom action

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
action_item do
link_to "Do smth", dosmth_admin_products_path
end
collection_action :dosmth, :method => :get do
end
controller do
...
def dosmth
# do some stuff
# shows view '/admin/products/dosmth.html.haml'
#render 'dosmth'
end
end
ActiveAdmin.register Product do
index :as => :table do
column :title
column :price
actions
end
end
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
%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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment