Last active
June 8, 2022 19:10
-
-
Save maxivak/204f414f592774946276 to your computer and use it in GitHub Desktop.
ActiveAdmin custom action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
action_item do | |
link_to "Do smth", dosmth_admin_products_path | |
end | |
collection_action :dosmth, :method => :get do | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
controller do | |
... | |
def dosmth | |
# do some stuff | |
# shows view '/admin/products/dosmth.html.haml' | |
#render 'dosmth' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveAdmin.register Product do | |
index :as => :table do | |
column :title | |
column :price | |
actions | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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
Thank you, it was helpful