如何编辑或覆盖ActiveAdmin的页脚?
如何编辑或覆盖Active_Admin的页脚?
回答:
在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
别忘了! 重启 app / server。
任何ActiveAdmin布局组件都可以像这样自定义。
更多关于它:
它为什么有效? 这是Ruby的神奇酱油。 我们正在重新打开Footer类的定义并将其更改为我们的自定义内容。
它是完全可定制的吗? 我不知道。 这是inheritance路径:
ActiveAdmin
class Component < Arbre::Component class Footer < Component
ARBRE
class Component < Arbre::HTML::Div
这意味着我们可以直接使用Arbre的DSL。
如果您只想更改或删除“powered by”消息,您可以做的是在区域设置文件中更改其值。 例如,编辑config/locales/en.yml
并使用这样的东西:
en: active_admin: powered_by: "Powered by hamsters"
为何如此有效:
rails应用程序的默认语言环境是英语, en
语言环境文件。
来自lib/footer.rb
gist创建文件
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
在v1.0.4pre和v.1.0.5pre之间,先前覆盖Footer#build
方法不再有效,新的API是
ActiveAdmin.application.footer = proc { ... }
对于v.1.0.0.pre5,我发现接受的答案需要一个小的附加,即添加一个变量来构建如下:
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