Skip to content

Instantly share code, notes, and snippets.

@brenes
Last active December 19, 2015 07:09
Show Gist options
  • Select an option

  • Save brenes/5916893 to your computer and use it in GitHub Desktop.

Select an option

Save brenes/5916893 to your computer and use it in GitHub Desktop.
Refinery Admin extension solving Globalize + Crudify issues
# Extension to Refinery Admin controller to avoid 2 problems:
#
# 1) Edit locale propagates through requests as Thread.current[:globalize_locale] is never reset to nil
# 2) Crudify's find filter is pepended before de globalize filter. This way, if you're editing in a non-default locale and the update url comes with a slug in that locale it won't be found (in fact, it does work in some circunstances)
::Refinery::AdminController.class_eval do
# We should reset globalize so we don't propagate Globalize locale between requests
def reset_globalize
Thread.current[:globalize_locale] = nil
I18n.locale = params['switch_locale'].to_sym unless params['switch_locale'].nil?
globalize!
end
# We should prepend the globalize filter after crudify or else we would search for a slug before the locale is loaded
def self.crudify *args
super *args
prepend_before_filter :reset_globalize
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment