Skip to content
Snippets Groups Projects
Unverified Commit 3c0bc2d0 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

current website language is calculated model-side

parent 93e2e8ca
No related branches found
No related tags found
No related merge requests found
......@@ -7,11 +7,7 @@ class Admin::Communication::Websites::ApplicationController < Admin::Communicati
protected
def current_website_language
@current_website_language ||= begin
language = @website.languages.find_by(iso_code: params[:lang])
language ||= @website.default_language
language
end
@current_website_language ||= @website.best_language_for(params[:lang])
end
helper_method :current_website_language
......
......@@ -98,6 +98,12 @@ class Communication::Website < ApplicationRecord
dependencies
end
def best_language_for(iso_code)
# We look for the language by the ISO code in the websites languages.
# If not found, we fallback to the default language.
languages.find_by(iso_code: iso_code) || default_language
end
protected
def languages_must_include_default_language
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment