site_controller.rb
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module Kanjai
class SiteController < ApplicationController
layout false
#protect_from_forgery
before_action :define_locale
before_action :get_page
include Kanjai::ContentFunction
private
def default_url_options(options={})
if params && params[:locale] || @current_controller == 'pages'
{ :locale => I18n.locale }
else
{}
end
end
def define_locale
if params && params[:locale].present? && request.original_fullpath.split('/')[1].length == 2
I18n.locale = params[:locale]
elsif Kanjai::PageLang.where(default_use: true).first
I18n.locale = Kanjai::PageLang.where(default_use: true).first.code
else
I18n.locale = Rails.application.config.i18n.default_locale
end
end
def get_page
@url = get_page_url
$original_fullpath = request.original_fullpath
$original_format = request.format
#@page_data = PageDatum.where(:url => @url).first
#$current_locale = PageLang.where(default_use: true).first.code
@page_data = PageDatum.where(:url => @url, lang: I18n.locale).first
$current_locale = I18n.locale
if @page_data.nil?
mas = @url.split('/')
if mas.length > 1
@url = '/' + mas[1] + '/:path'
@page_data = PageDatum.where(:url => @url, lang: I18n.locale).first
end
end
if @page_data
#$current_locale = @page_data.lang
else
if @url == '/'
root_page = Page.where(root_page: true).first
if root_page
redirect_to root_page.menu_url($scheme)
end
end
end
$url = @url
end
end
end