Commit d7e254323cc6e159648cc2d0b96b41a5c4c2a56c

Authored by Andrey Karpikov
1 parent 3e7199b4

check get current page and dynamic segment

... ... @@ -74,7 +74,9 @@ module Kanjai
74 74
75 75 #@page_data = PageDatum.where(:url => @url).first
76 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 81 session[:current_locale] = I18n.locale
80 82 #if @page_data.nil?
... ... @@ -109,6 +111,7 @@ module Kanjai
109 111 end
110 112 session[:url] = @url
111 113 session[:current_page_id] = @page_data.page.id
  114 + session[:page_params] = @page_params
112 115 end
113 116
114 117
... ...
... ... @@ -14,9 +14,23 @@ module Kanjai
14 14 root_page = nil
15 15 page_datum = nil
16 16
  17 + params = {}
  18 +
17 19 loop do
18 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 34 page_datum = nil
21 35 end
22 36 end
... ... @@ -44,6 +58,7 @@ module Kanjai
44 58 page_datum = sheck_scope.find_by(url: "/#{work_url}") if page_datum.nil?
45 59 page_datum = sheck_scope.find_by(url: "#{work_url}/") if page_datum.nil?
46 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 63 if page_datum
49 64 root_page = page_datum.page
... ... @@ -60,7 +75,7 @@ module Kanjai
60 75 page_datum = scope.find_by(url: url)
61 76 end
62 77
63   - page_datum
  78 + {page: page_datum, params: params}
64 79 end
65 80
66 81 private
... ...
... ... @@ -176,6 +176,9 @@ module Kanjai
176 176 self.text_html.to_s
177 177 elsif self.type_content == 'plugin'
178 178 controller = self.controller_name.constantize.new
  179 + controller.instance_variable_set(:@page_params, session[:page_params])
  180 +
  181 +
179 182 controller.send self.action_name
180 183 controller_variables = controller.instance_variables
181 184 hash = {}
... ...
1 1 module Kanjai
2   - VERSION = "0.0.346"
  2 + VERSION = "0.0.347"
3 3 end
... ...