Skip to content

Commit

Permalink
Store the current exhibit in a thread-local variable for selecting i1…
Browse files Browse the repository at this point in the history
…8n translations; fixes #2014
  • Loading branch information
cbeer authored and Jessie Keck committed Apr 20, 2018
1 parent 6e0d93f commit 5c75ff8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/spotlight/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Controller
end

def set_exhibit_locale_scope
Translation.exhibit_default_scope(current_exhibit)
Translation.current_exhibit = current_exhibit
end

def current_site
Expand Down
9 changes: 7 additions & 2 deletions app/models/concerns/spotlight/custom_translation_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ module CustomTranslationExtension
extend ActiveSupport::Concern

included do
default_scope { where(exhibit: current_exhibit) }
belongs_to :exhibit, class_name: 'Spotlight::Exhibit', inverse_of: :translations
end

class_methods do
def exhibit_default_scope(exhibit)
default_scope { where(exhibit: exhibit) }
def current_exhibit
Thread.current[:current_exhibit]
end

def current_exhibit=(exhibit)
Thread.current[:current_exhibit] = exhibit
end
end
end
Expand Down

0 comments on commit 5c75ff8

Please sign in to comment.