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

Fix 'Pages' list on admin #3327

Closed

Conversation

takacszoltansandor
Copy link

Issue:
'Pages' list doesn't work in the admin area.

Error description:
ActionView::Template::Error (comparison of Fixnum with nil failed):
25:
26: <% if Refinery::I18n.frontend_locales.many? %>
27:
28: <% page.translations.sort_by{ |t| Refinery::I18n.frontend_locales.index(t.locale)}.each do |translation| %>
29: <% if translation.title.present? %>
30: <%= link_to refinery.admin_edit_page_path(page.nested_url, switch_locale: translation.locale),
31: class: 'locale', title: translation.locale.upcase do %>
app/views/refinery/admin/pages/_page.html.erb:28

How to reproduce:

  1. Add 'a' and 'b' locales to frontend_locales.
    config.frontend_locales = [:a, :b]
  2. Create 'b' translation for a page.
  3. Remove 'b' locale from frontend_locales.
    config.frontend_locales = [:a]
  4. Load 'Pages' listing page in admin.

Cause:
Refinery tries to sort page translations based on their locale's position in frontend_locales array.
Once locale is removed, sort tries to compare nil as position index with a Fixnum.

Issue:
'Pages' list doesn't work in the admin area.

Error description:
ActionView::Template::Error (comparison of Fixnum with nil failed):
25:
26: <% if Refinery::I18n.frontend_locales.many? %>
27:   <span class='locales'>
28:     <% page.translations.sort_by{ |t| Refinery::I18n.frontend_locales.index(t.locale)}.each do |translation| %>
29:       <% if translation.title.present? %>
30:         <%= link_to refinery.admin_edit_page_path(page.nested_url, switch_locale: translation.locale),
31:                     class: 'locale', title: translation.locale.upcase do %>
app/views/refinery/admin/pages/_page.html.erb:28

How to reproduce:
1. Add 'a' and 'b' locales to frontend_locales.
config.frontend_locales = [:a, :b]
2. Create 'b' translation for a page.
3. Remove 'b' locale from frontend_locales.
config.frontend_locales = [:a]
4. Load 'Pages' listing page in admin.

Cause:
Refinery tries to sort page translations based on their locale's position in frontend_locales array.
Once locale is removed, sort tries to compare nil as position index with a Fixnum.
@takacszoltansandor
Copy link
Author

I've found this pull-request: 79ae307

This a different, a fault-tolerant approach for the same problem.

@bricesanchez
Copy link
Member

@takacszoltansandor Thanks for you contribution, we need a test case for #3308 in order to be merged. Could you help us?

@bricesanchez bricesanchez added this to the 4.0.2 milestone Mar 7, 2018
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.

2 participants