【问题标题】:How do I edit or override the footer of ActiveAdmin?如何编辑或覆盖 ActiveAdmin 的页脚?
【发布时间】:2013-12-09 06:43:50
【问题描述】:

如何编辑或覆盖 Active_Admin 的页脚?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 activeadmin


    【解决方案1】:

    答案:

    在您的 rails 应用程序中,创建此文件:app/admin/footer.rb

    内容大概是这样的:

    module ActiveAdmin
      module Views
        class Footer < Component
    
          def build
            super :id => "footer"                                                    
            super :style => "text-align: right;"                                     
    
            div do                                                                   
              small "Cool footer #{Date.today.year}"                                       
            end
          end
    
        end
      end
    end
    

    别忘了! 重启应用/服务器。

    任何 ActiveAdmin 布局组件都可以这样定制。

    更多信息:

    为什么有效? 这是鲁比的魔法酱。我们正在重新定义 Footer 类并针对我们的自定义内容进行更改。

    它是完全可定制的吗?我不知道。这是继承路径:

    活动管理

    class Component < Arbre::Component
    class Footer < Component
    

    阿布雷

    class Component < Arbre::HTML::Div
    

    这意味着我们可以直接使用Arbre的DSL。

    【讨论】:

    • 构建现在需要一个参数,build(namespace)
    【解决方案2】:

    如果您只想更改或删除“由”消息,您可以做的是更改其在语言环境文件中的值。例如,编辑config/locales/en.yml

    并使用这样的东西:

    en:                                                                              
      active_admin:                                                                  
        powered_by: "Powered by hamsters"
    

    为什么会这样:

    rails 应用程序的默认语言环境是英语,即en 语言环境文件。

    【讨论】:

    • 不错,正是我需要的
    【解决方案3】:

    对于 v.1.0.0.pre5,我发现 Accepted Answer 需要一个小的添加,即添加一个要构建的变量,如下所示:

    module ActiveAdmin
      module Views
        class Footer < Component
    
          def build (namespace)
            super :id => "footer"                                                    
            super :style => "text-align: right;"                                     
    
            div do                                                                   
              small "Cool footer #{Date.today.year}"                                       
            end
          end
    
        end
      end
    end
    

    【讨论】:

      【解决方案4】:

      来自gistlib/footer.rb创建文件

      class Footer < ActiveAdmin::Component
        def build
          super :id => "footer"
          span "My Awesome footer"
        end
      end
      

      添加到initializers/active_admin.rb

      ActiveAdmin.setup do |config|
       ......some config here....
      
        config.view_factory.footer = Footer
      
       ......some config here....
      end
      

      【讨论】:

      • 我不知道应该使用什么lib 文件夹。也许它适用于旧版本。我猜你的意思是app/admin/
      • 不,我的意思是lib/ 文件夹,我在我的项目中使用了这个功能。
      • 这应该是公认的答案,恕我直言。 Monkey patching 可能在短期内有效,但从长远来看,它带来的问题比它解决的问题要多。
      【解决方案5】:

      在 v1.0.4pre 和 v.1.0.5pre 之间,之前覆盖 Footer#build 的方法不再有效,新的 API 是

      ActiveAdmin.application.footer = proc {
        ...
      }
      

      【讨论】:

        【解决方案6】:

        较新版本的 ActiveAdmin 提供了可配置的选项来设置页脚。

        ActiveAdmin Footer Customization

        config.footer = "MyApp Revision v1.3"

        可以使用 proc 配置页脚,甚至可以在其中渲染部分。

        ActiveAdmin Footer Customization using proc

        config.footer = proc { "Enjoy MyApp Revision 123, #{controller.current_admin_user.try(:email)}!" }

        PR which added the ability to customize the footer

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-11-15
          • 2022-10-04
          • 1970-01-01
          相关资源
          最近更新 更多