Commit 858ef94a411ce2d008f2a89aceae4aeb7d7d5890

Authored by Andrey Karpikov
1 parent d7e25432

check robots.txt and error with styles

... ... @@ -5,10 +5,34 @@ module Kanjai
5 5 #protect_from_forgery
6 6
7 7 #before_action :define_locale
8   - before_action :get_page
  8 + before_action :get_page, except: [:robots, :sitemap]
9 9
10 10 include Kanjai::ContentFunction
11 11
  12 + def robots
  13 + domain_title = request.domain
  14 + if request.subdomain.to_s.present?
  15 + domain_title = "#{request.subdomain}.#{domain_title}"
  16 + end
  17 +
  18 + domain = Domain.find_by(title: domain_title)
  19 + render_text = ""
  20 + if domain
  21 + render_text = domain.robots.to_s
  22 + end
  23 +
  24 + render plain: render_text
  25 + end
  26 +
  27 + def sitemap
  28 + domain_title = request.domain
  29 + if request.subdomain.to_s.present?
  30 + domain_title = "#{request.subdomain}.#{domain_title}"
  31 + end
  32 +
  33 + domain = Domain.find_by(title: domain_title)
  34 + end
  35 +
12 36 private
13 37
14 38 def default_url_options(options={})
... ...
1 1 module Kanjai
2 2 class Domain < ApplicationRecord
3   - after_save :generate_robots_file
4   -
5 3 validates :title, presence: true
6 4
7 5 belongs_to :default_lang, class_name: 'Kanjai::PageLang', optional: true
... ... @@ -13,14 +11,5 @@ module Kanjai
13 11
14 12 belongs_to :page_404, class_name: "Kanjai::Page", optional: true
15 13
16   -
17   - private
18   -
19   - def generate_robots_file
20   - if saved_change_to_robots?
21   - File.open("#{Rails.root}/public/robots.txt", 'w') { |file| file.write(robots) }
22   - end
23   - end
24   -
25 14 end
26 15 end
... ...
... ... @@ -176,7 +176,7 @@ 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])
  179 + controller.instance_variable_set(:@page_params, session[:page_params]) if session.present?
180 180
181 181
182 182 controller.send self.action_name
... ...
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  3 +
  4 +</urlset>
\ No newline at end of file
... ...
... ... @@ -67,8 +67,13 @@ Kanjai::Engine.routes.draw do
67 67
68 68 end
69 69
  70 + match 'robots.txt' => 'site#robots', via: :get
  71 + match 'sitemap.xml' => 'site#sitemap', via: :get
  72 +
70 73 scope "(:locale)", :locale => /#{I18n.available_locales.join("|")}/ do
71 74 match 'form/:page_content_id' => 'form#index', via: [:get, :post], as: 'form'
72 75 match '*path' => 'pages#show', via: :all
73 76 end
  77 +
  78 +
74 79 end
... ...
1 1 module Kanjai
2   - VERSION = "0.0.347"
  2 + VERSION = "0.0.348"
3 3 end
... ...