Module: MultiSite::SiteControllerExtensions

Defined in:
lib/multi_site/site_controller_extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
5
6
7
# File 'lib/multi_site/site_controller_extensions.rb', line 2

def self.included(base)
  base.class_eval do
    before_filter :set_site
    alias_method_chain :process_page, :home_path
  end
end

Instance Method Details

#process_page_with_home_path(page) ⇒ Object

If it’s a file not found page and the path doesn’t include the site’s homepage path, try redirecting to include it.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/multi_site/site_controller_extensions.rb', line 11

def process_page_with_home_path(page)
  homepage = Page.current_site.homepage
  if page.is_a?(FileNotFoundPage) && !params[:url].include?(homepage.slug)
    if homepage.slug != "/"
      false if redirect_to "/#{homepage.slug}/#{params[:url]}"
    else
      process_page_without_home_path(page)
    end
  else
    process_page_without_home_path(page)
  end

end

#set_siteObject



25
26
27
28
# File 'lib/multi_site/site_controller_extensions.rb', line 25

def set_site
  Page.current_site = Site.find_for_host(request.host)
  true
end