Commit d7e254323cc6e159648cc2d0b96b41a5c4c2a56c

Authored by Andrey Karpikov
1 parent 3e7199b4

check get current page and dynamic segment

@@ -74,7 +74,9 @@ module Kanjai @@ -74,7 +74,9 @@ module Kanjai
74 74
75 #@page_data = PageDatum.where(:url => @url).first 75 #@page_data = PageDatum.where(:url => @url).first
76 #$current_locale = PageLang.where(default_use: true).first.code 76 #$current_locale = PageLang.where(default_use: true).first.code
77 - @page_data = CurrentPage.new(domain: domain, lang: I18n.locale, url: @url).call 77 + res = CurrentPage.new(domain: domain, lang: I18n.locale, url: @url).call
  78 + @page_data = res[:page]
  79 + @page_params = res[:params]
78 80
79 session[:current_locale] = I18n.locale 81 session[:current_locale] = I18n.locale
80 #if @page_data.nil? 82 #if @page_data.nil?
@@ -109,6 +111,7 @@ module Kanjai @@ -109,6 +111,7 @@ module Kanjai
109 end 111 end
110 session[:url] = @url 112 session[:url] = @url
111 session[:current_page_id] = @page_data.page.id 113 session[:current_page_id] = @page_data.page.id
  114 + session[:page_params] = @page_params
112 end 115 end
113 116
114 117
@@ -14,9 +14,23 @@ module Kanjai @@ -14,9 +14,23 @@ module Kanjai
14 root_page = nil 14 root_page = nil
15 page_datum = nil 15 page_datum = nil
16 16
  17 + params = {}
  18 +
17 loop do 19 loop do
18 if mas.count == 0 && page_datum 20 if mas.count == 0 && page_datum
19 - if page_datum.page.menu_url('http', lang) != "/#{lang}#{url}" 21 + page_url = page_datum.page.menu_url('http', lang)
  22 + regust_url = "/#{lang}#{url}"
  23 +
  24 + page_url_mas = page_url.split('/')
  25 + regust_url_mas = regust_url.split('/')
  26 + page_url_mas.each_with_index do |segment, index|
  27 + if segment == ':param'
  28 + page_url_mas[index] = regust_url_mas[index]
  29 + params[:param] = regust_url_mas[index]
  30 + end
  31 + end
  32 +
  33 + if page_url_mas.join('/') != regust_url_mas.join('/')
20 page_datum = nil 34 page_datum = nil
21 end 35 end
22 end 36 end
@@ -44,6 +58,7 @@ module Kanjai @@ -44,6 +58,7 @@ module Kanjai
44 page_datum = sheck_scope.find_by(url: "/#{work_url}") if page_datum.nil? 58 page_datum = sheck_scope.find_by(url: "/#{work_url}") if page_datum.nil?
45 page_datum = sheck_scope.find_by(url: "#{work_url}/") if page_datum.nil? 59 page_datum = sheck_scope.find_by(url: "#{work_url}/") if page_datum.nil?
46 page_datum = sheck_scope.find_by(url: "/#{work_url}/") if page_datum.nil? 60 page_datum = sheck_scope.find_by(url: "/#{work_url}/") if page_datum.nil?
  61 + page_datum = sheck_scope.find_by(url: ":param") if page_datum.nil? && check_length == 1
47 62
48 if page_datum 63 if page_datum
49 root_page = page_datum.page 64 root_page = page_datum.page
@@ -60,7 +75,7 @@ module Kanjai @@ -60,7 +75,7 @@ module Kanjai
60 page_datum = scope.find_by(url: url) 75 page_datum = scope.find_by(url: url)
61 end 76 end
62 77
63 - page_datum 78 + {page: page_datum, params: params}
64 end 79 end
65 80
66 private 81 private
@@ -176,6 +176,9 @@ module Kanjai @@ -176,6 +176,9 @@ module Kanjai
176 self.text_html.to_s 176 self.text_html.to_s
177 elsif self.type_content == 'plugin' 177 elsif self.type_content == 'plugin'
178 controller = self.controller_name.constantize.new 178 controller = self.controller_name.constantize.new
  179 + controller.instance_variable_set(:@page_params, session[:page_params])
  180 +
  181 +
179 controller.send self.action_name 182 controller.send self.action_name
180 controller_variables = controller.instance_variables 183 controller_variables = controller.instance_variables
181 hash = {} 184 hash = {}
1 module Kanjai 1 module Kanjai
2 - VERSION = "0.0.346" 2 + VERSION = "0.0.347"
3 end 3 end