如何编辑或覆盖Active_Admin的页脚?
答案 0 :(得分:21)
<强>答案:强>
在您的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布局组件都可以像这样自定义。
有关它的更多信息:
为什么会这样? 这是Ruby的神奇酱油。我们正在重新打开Footer类的定义并为我们的自定义内容更改它。
它是完全可定制的吗?我不知道。这是继承路径:
ActiveAdmin
class Component < Arbre::Component
class Footer < Component
ARBRE
class Component < Arbre::HTML::Div
这意味着我们可以直接使用Arbre的DSL。
答案 1 :(得分:15)
如果你想要做的就是改变或删除由&#39;提供支持的&#39;消息,您可以做的是更改其在区域设置文件中的值。例如,编辑config/locales/en.yml
使用类似的东西:
en:
active_admin:
powered_by: "Powered by hamsters"
为什么会这样:
rails应用程序的默认语言环境是英语,en
语言环境文件。
答案 2 :(得分:3)
来自gist
在lib/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
答案 3 :(得分:2)
在v1.0.4pre和v.1.0.5pre之间,先前的覆盖Footer#build
的方法不再有效,新的API是
ActiveAdmin.application.footer = proc {
...
}
答案 4 :(得分:2)
对于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
答案 5 :(得分:0)
较新版本的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)}!" }