custom action not appearing in UI

48 views
Skip to first unread message

Andy Kriger

unread,
May 17, 2019, 1:29:24 PM5/17/19
to rails_admin
Hi,

I have a custom action but it does not show up in the UI.
If I put the action directly into the RailsAdmin configuration file it works, but storing it in a separate file in lib, I do not see it in the UI.
It's taken quite a bit of tinkering just to get it so that the server doesn't fail on startup because of bad configuration.
For example, the file had to be properly nested in lib and required in rails_admin.rb (which is not what the wiki says).
Can anyone help me figure out why the link isn't showing up on the List views?

thanks
a

In lib/rails_admin/config/actions/upload_file.rb

require 'rails_admin/config/actions'
require 'rails_admin/config/actions/base'

module RailsAdmin
  module Config
    module Actions
      class UploadFile < RailsAdmin::Config::Actions::Base
        RailsAdmin::Config::Actions.register(self)

        register_instance_option :link_icon do
          "icon-upload"
        end

        register_instance_option :collection? do
          true
        end

        register_instance_option :http_methods do
          %i[GET POST]
        end

        register_instance_option :controller do
          proc do
            puts "OH HAI HEY NOW"
            redirect_to "/admin"
          end
        end
      end
    end
  end
end

In config/initializers/rails_admin.rb
require "./lib/rails_admin/config/actions/upload_file"
...
config.actions do
    dashboard                     # mandatory
    index                         # mandatory
    new do
      check_visibility
    end
    export
    bulk_delete do
      check_visibility
    end
    show
    edit do
      check_visibility
    end
    delete do
      check_visibility
    end
    show_in_app
    upload_file
end

in config/rails_admin.en.yml
en:
  admin:
    actions:
      upload_file:
        title: "Upload %{model_label}"
        menu: "Upload file"
        breadcrumb: "Upload"
        link: "Upload a %{model_label}"
        done: "uploaded"

rake routes
Routes for RailsAdmin::Engine:
  dashboard GET         /                                      rails_admin/main#dashboard
      index GET|POST    /:model_name(.:format)                 rails_admin/main#index
        new GET|POST    /:model_name/new(.:format)             rails_admin/main#new
     export GET|POST    /:model_name/export(.:format)          rails_admin/main#export
bulk_delete POST|DELETE /:model_name/bulk_delete(.:format)     rails_admin/main#bulk_delete
upload_file GET|POST    /:model_name/upload_file(.:format)     rails_admin/main#upload_file
bulk_action POST        /:model_name/bulk_action(.:format)     rails_admin/main#bulk_action
       show GET         /:model_name/:id(.:format)             rails_admin/main#show
       edit GET|PUT     /:model_name/:id/edit(.:format)        rails_admin/main#edit
     delete GET|DELETE  /:model_name/:id/delete(.:format)      rails_admin/main#delete
show_in_app GET         /:model_name/:id/show_in_app(.:format) rails_admin/main#show_in_app

Andy Kriger

unread,
May 19, 2019, 11:33:26 AM5/19/19
to rails_admin
This was failing because 
register_instance_option :http_methods do
  %i[GET POST]
end

needed to be
register_instance_option :http_methods do
  %i[get post] # lowercase
end

Opening a bug on this
Reply all
Reply to author
Forward
0 new messages