Module: MultiSite::PageExtensions
- Defined in:
- lib/multi_site/page_extensions.rb
Overview
Unlike other scoped classes, there is no site association in the Page class. Instead, Site has a homepage association and Page has some retrieval methods that turn a page request into site information.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/multi_site/page_extensions.rb', line 4 def self.included(base) base.class_eval { include InstanceMethods alias_method_chain :url, :sites mattr_accessor :current_site belongs_to :site before_create :associate_with_site } base.extend ClassMethods class << base def find_by_path(path, live=true) root = homepage raise Page::MissingRootPageError unless root path = root.path if clean_path(path) == "/" result = root.find_by_path(path, live) # If the result is a FileNotFoundPage and it # doesn't match the current site, try to find one that does. if result.is_a?(FileNotFoundPage) && result.site_id != homepage.site_id get_site_specific_file_not_found(result) # Otherwise, just go with it. else result end end def current_site @current_site ||= Site.default end def current_site=(site) @current_site = site end def clean_path(path) "/#{ path.to_s.strip }/".gsub(%r{//+}, '/') end # if the result is a FileNotFoundPage, try to find the one for this site. # if you can't, return the initial result def get_site_specific_file_not_found(result) site_file_not_founds = FileNotFoundPage.where(site_id: homepage.site_id) site_file_not_founds.any? ? site_file_not_founds.first : result end end end |
Instance Method Details
#url_with_sites ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/multi_site/page_extensions.rb', line 73 def url_with_sites if parent parent.child_url(self) else "/" end end |