Fix: Redirect to portal with default locale (#5467)
- Redirect to default locale if URL does not provide the locale param
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
class Public::Api::V1::PortalsController < PublicController
|
class Public::Api::V1::PortalsController < PublicController
|
||||||
before_action :ensure_custom_domain_request, only: [:show]
|
before_action :ensure_custom_domain_request, only: [:show]
|
||||||
|
before_action :redirect_to_portal_with_locale, only: [:show]
|
||||||
before_action :portal
|
before_action :portal
|
||||||
layout 'portal'
|
layout 'portal'
|
||||||
|
|
||||||
@@ -9,5 +10,12 @@ class Public::Api::V1::PortalsController < PublicController
|
|||||||
|
|
||||||
def portal
|
def portal
|
||||||
@portal ||= Portal.find_by!(slug: params[:slug], archived: false)
|
@portal ||= Portal.find_by!(slug: params[:slug], archived: false)
|
||||||
|
@locale = params[:locale] || @portal.default_locale
|
||||||
|
end
|
||||||
|
|
||||||
|
def redirect_to_portal_with_locale
|
||||||
|
return if params[:locale].present?
|
||||||
|
|
||||||
|
redirect_to "/hc/#{@portal.slug}/#{@portal.default_locale}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<%= render "public/api/v1/portals/hero", portal: @portal %>
|
<%= render "public/api/v1/portals/hero", portal: @portal %>
|
||||||
<div class="max-w-5xl w-full flex-grow mx-auto py-8 px-4">
|
<div class="max-w-5xl w-full flex-grow mx-auto py-8 px-4">
|
||||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-x-32 gap-y-0 lg:gap-y-12">
|
<div class="grid grid-cols-1 lg:grid-cols-2 gap-x-32 gap-y-0 lg:gap-y-12">
|
||||||
<% @portal.categories.where(locale: params[:locale]).each do |category| %>
|
<% @portal.categories.where(locale: @locale).each do |category| %>
|
||||||
<%= render "public/api/v1/portals/category-block", category: category, portal: @portal %>
|
<%= render "public/api/v1/portals/category-block", category: category, portal: @portal %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -287,6 +287,7 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get 'hc/:slug', to: 'public/api/v1/portals#show'
|
||||||
get 'hc/:slug/:locale', to: 'public/api/v1/portals#show'
|
get 'hc/:slug/:locale', to: 'public/api/v1/portals#show'
|
||||||
get 'hc/:slug/:locale/categories', to: 'public/api/v1/portals/categories#index'
|
get 'hc/:slug/:locale/categories', to: 'public/api/v1/portals/categories#index'
|
||||||
get 'hc/:slug/:locale/:category_slug', to: 'public/api/v1/portals/categories#show'
|
get 'hc/:slug/:locale/:category_slug', to: 'public/api/v1/portals/categories#show'
|
||||||
|
|||||||
Reference in New Issue
Block a user