Skip to content
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

Merged
merged 1 commit into from
Sep 12, 2012

Conversation

shell
Copy link
Contributor

@shell shell commented Sep 12, 2012

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

jpmckinney pushed a commit that referenced this pull request Sep 12, 2012
#1652 - Added support of Proc object at menu :parent option
@jpmckinney jpmckinney merged commit 3d6976c into activeadmin:master Sep 12, 2012
@jpmckinney
Copy link
Contributor

Merged, thanks!

@mspanc
Copy link
Contributor

mspanc commented Jan 21, 2013

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

["/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activesupport-3.2.11/lib/active_support/locale/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activemodel-3.2.11/lib/active_model/locale/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activerecord-3.2.11/lib/active_record/locale/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/actionpack-3.2.11/lib/action_view/locale/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/meta_search-1.1.3/lib/meta_search/locale/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/responders-0.9.3/lib/responders/locales/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/paperclip-3.3.1/lib/paperclip/locales/en.yml"]
[]
[:en]
"translation missing: pl.admin"
pl
en
translation missing: pl.admin.menu.broadcasts
translation missing: pl.admin.menu.broadcasts

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:

["/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/da.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/de.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/lv.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/it.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/pl.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/ja.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/sv-SE.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/ro.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/fr.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/es.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/no-NB.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/nl.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/zh-TW.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/hr.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/ko.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/vi.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/ca.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/bg.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/hu.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/zh-CN.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/pt-BR.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/tr.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/lt.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/he.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/cs.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activeadmin-0.5.1/lib/active_admin/locales/ru.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activesupport-3.2.11/lib/active_support/locale/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activemodel-3.2.11/lib/active_model/locale/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/activerecord-3.2.11/lib/active_record/locale/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/actionpack-3.2.11/lib/action_view/locale/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/meta_search-1.1.3/lib/meta_search/locale/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/responders-0.9.3/lib/responders/locales/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/paperclip-3.3.1/lib/paperclip/locales/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/devise-2.2.2/config/locales/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/kaminari-0.14.1/config/locales/kaminari.yml", "/home/marcin/aktivitis/lemko-scheduler2/config/locales/core.pl.yml", "/home/marcin/aktivitis/lemko-scheduler2/config/locales/devise.en.yml", "/home/marcin/aktivitis/lemko-scheduler2/config/locales/devise.pl.yml", "/home/marcin/aktivitis/lemko-scheduler2/config/locales/en.yml", "/home/marcin/aktivitis/lemko-scheduler2/config/locales/pl.yml", "/home/marcin/aktivitis/lemko-scheduler2/config/locales/time_combined_input.pl.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/just-datetime-picker-0.0.5/lib/just-datetime-picker/locales/pl.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/just-datetime-picker-0.0.5/lib/just-datetime-picker/locales/en.yml", "/home/marcin/.rvm/gems/ruby-1.9.3-p286@lemko_scheduler/gems/just-datetime-picker-0.0.5/lib/just-datetime-picker/locales/zh-CN.yml"]

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

@mspanc
Copy link
Contributor

mspanc commented Jan 21, 2013

I had to follow http://stackoverflow.com/questions/7193043/activeadmin-internationalization to make it working, is it possible to incorporate this into AA?

@seanlinsley
Copy link
Contributor

The proc is only being called once, independent of whether you call I18n. A simple test:

menu :parent => proc{ rand.to_s }

@mspanc
Copy link
Contributor

mspanc commented Jan 21, 2013

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.

@seanlinsley
Copy link
Contributor

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.

@seanlinsley
Copy link
Contributor

Okay I've pushed fixes to my PR. Now parents properly support procs.

@mspanc
Copy link
Contributor

mspanc commented Jan 22, 2013

Cool, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants