How can I customize the active admin layout?

后端 未结 5 949
梦如初夏
梦如初夏 2021-01-31 09:42

I need to customize the active admin layout, but how can I do it?

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 10:26

    (Using rails 5.1.4) I tried two solutions here that involved messing with the active_admin library, and they did not work for me at all. I found my solution in config/initializers/active_admin.rb. I am adding a small amount of bootstrap styling to the default layout. As far as linking to stylesheets, javascripts, etc., it was as simple as adding this to my active_admin.rb, as per the comments therein:

      # == Register Stylesheets & Javascripts
      #
      # We recommend using the built in Active Admin layout and loading
      # up your own stylesheets / javascripts to customize the look
      # and feel.
      #
      # To load a stylesheet:
      #   config.register_stylesheet 'my_stylesheet.css'
      config.register_stylesheet 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css', { integrity: 'sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk', crossorigin: 'anonymous' }
    

    As far as editing that generated layout, I have yet to figure it out, but it could at least be done indirectly via JavaScript and the inclusion of that javascipt in this file via

    config.register_javascript 'active_admin_view_tweaks.js', { defer: true }
    

    I am going to be editing class attributes to make my pages responsive with bootstrap, so I might follow something like this geeksforgeeks article to edit the pages with JavaScript after they've loaded.

    I don't know if there is a way to edit the generated layout more directly, but this should work for some cases.

提交回复
热议问题