问题
How do I edit or override the footer of Active_Admin?
回答1:
Answer:
In your rails app, create this file: app/admin/footer.rb
The content would be something like:
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
Don't forget! restart the app/server.
Any ActiveAdmin layout component can be customized like this.
More about it:
Why does it work? This is Ruby's magic sauce. We are reopening the definition of the Footer class and changing it for our custom content.
Is it totally customizable? I don't know. This is the inheritance path:
ActiveAdmin
class Component < Arbre::Component
class Footer < Component
Arbre
class Component < Arbre::HTML::Div
This means that we can use Arbre's DSL directly.
回答2:
If all you want to do is change or delete the 'powered by' message, what you can do is change its value in a locale file. Example, edit config/locales/en.yml
And use something like this:
en:
active_admin:
powered_by: "Powered by hamsters"
Why this works:
The default locale for a rails app is english, the en
locale file.
回答3:
From gist
create file in lib/footer.rb
class Footer < ActiveAdmin::Component
def build
super :id => "footer"
span "My Awesome footer"
end
end
add to initializers/active_admin.rb
ActiveAdmin.setup do |config|
......some config here....
config.view_factory.footer = Footer
......some config here....
end
回答4:
For v.1.0.0.pre5 I found that the Accepted Answer requires a small additiion, namely adding a variable to build as below:
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:
Between v1.0.4pre and v.1.0.5pre, the previous method of overriding Footer#build
no longer works well, and the new API is
ActiveAdmin.application.footer = proc {
...
}
回答6:
Newer version of ActiveAdmin provides configurable option to set footer.
ActiveAdmin Footer Customization
config.footer = "MyApp Revision v1.3"
Footer can be configured using proc, where you can even render partial.
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
来源:https://stackoverflow.com/questions/20464690/how-do-i-edit-or-override-the-footer-of-activeadmin