-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1652 - Added support of Proc object at menu :parent option #1664
#1652 - Added support of Proc object at menu :parent option #1664
Conversation
#1652 - Added support of Proc object at menu :parent option
Merged, thanks! |
It still does not work for me in 0.5.1. I've added following code for debugging: ActiveAdmin.register_page "BroadcastCalendar" do
menu :label => proc { I18n.t("admin.menu.broadcast_calendar") },
:parent => proc {
puts I18n.load_path.inspect
puts I18n.load_path.collect{ |x| x if x.include? "/lemko-scheduler" }.compact.inspect
puts I18n.available_locales.inspect
puts I18n.t("admin").inspect
puts I18n.locale
puts I18n.default_locale
puts I18n.t("admin.menu.broadcasts")
puts I18n.with_locale(:pl) { I18n.t("admin.menu.broadcasts") }
I18n.t("admin.menu.broadcasts") }
content do
div :id => "broadcast_calendar_container"
end
end The output is
the case is that the output is printed ONCE, during the startup of the server, not on every request. When I open console, and check load path, after the app is initialized, the output is:
Looks like activeadmin being loaded before Rails read all locales. Obviously it does not say why this proc is called only once. My gemfile: https://gist.github.com/4588813, gemfile.lock: https://gist.github.com/4588815 |
I had to follow http://stackoverflow.com/questions/7193043/activeadmin-internationalization to make it working, is it possible to incorporate this into AA? |
The proc is only being called once, independent of whether you call menu :parent => proc{ rand.to_s } |
What is the point in having Proc there if it is not reloaded on each request? I thought the whole concept of having Procs there is to allow reloading menu if e.g. user switches language, or any other dynamic condition happens, let's say someone wants to create menu like "Unread messages (5)" and then change it to "Unread messages (4)" if user reads the message. Even using current approach this Proc is called too early. |
The proc should definitely work that way -- the problem is this line of code which evaluates the proc before the MenuItem ever gets built. FYI I'm the author of PR #1488, which lets you better customize the parent menu item. As it happens, my PR breaks Procs for parent menu items... I'm writing a fix for that currently. |
Okay I've pushed fixes to my PR. Now parents properly support procs. |
Cool, thanks! |
I hadn't expirienced error mentioned at #1652. But to be sure I have added support of Proc object in menu :parent. Same as menu :label. Tests are passing now