Class: Cardboard::DynamicRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/cardboard/dynamic_router.rb

Class Method Summary collapse

Class Method Details

.loadObject



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
# File 'lib/cardboard/dynamic_router.rb', line 4

def self.load
  
  Rails.application.routes.draw  do
    return unless ActiveRecord::Base.connection.table_exists? :cardboard_urls
    Cardboard::Url.where("slugs_backup IS NOT NULL").each do |url|
      for link in url.slugs_backup
        get link, to: redirect(url.to_s)
      end
    end

    return unless ActiveRecord::Base.connection.table_exists? :cardboard_pages
    routes = @set.named_routes.routes
    Cardboard::Page.includes(:url_object, :template).each do |page|
      url = page.url_object
      template = page.template
      
      get url.to_s, :to => template.controller_action || "pages##{template.identifier}", defaults: { identifier: template.identifier }

      if !routes[:root] && page.root?
        root :to => template.controller_action || "pages##{template.identifier}"
      end
    end
  end

end

.reloadObject



30
31
32
# File 'lib/cardboard/dynamic_router.rb', line 30

def self.reload
  Rails.application.routes_reloader.reload!
end