Skip to content

Instantly share code, notes, and snippets.

@maxivak
Last active June 8, 2022 19:10
Show Gist options
  • Save maxivak/204f414f592774946276 to your computer and use it in GitHub Desktop.
Save maxivak/204f414f592774946276 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
@novikserg
Copy link

Thank you, it was helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment