Class: Alchemy::Site
- Inherits:
-
BaseRecord
- Object
- ActiveRecord::Base
- BaseRecord
- Alchemy::Site
- Includes:
- Layout
- Defined in:
- app/models/alchemy/site.rb
Defined Under Namespace
Modules: Layout
Constant Summary
Constants included from Layout
Class Method Summary collapse
- .current ⇒ Object
- .current=(site) ⇒ Object
- .default ⇒ Object
- .find_for_host(host) ⇒ Object
- .find_in_aliases(host) ⇒ Object
Instance Method Summary collapse
-
#current? ⇒ Boolean
Returns true if this site is the current site.
-
#default_language ⇒ Object
The default language for this site.
-
#to_partial_path ⇒ Object
Returns the path to site’s view partial.
Methods included from Layout
Methods inherited from BaseRecord
Class Method Details
.current ⇒ Object
62 63 64 |
# File 'app/models/alchemy/site.rb', line 62 def current RequestStore.store[:alchemy_current_site] || default end |
.current=(site) ⇒ Object
58 59 60 |
# File 'app/models/alchemy/site.rb', line 58 def current=(site) RequestStore.store[:alchemy_current_site] = site end |
.default ⇒ Object
66 67 68 |
# File 'app/models/alchemy/site.rb', line 66 def default Site.first || create_default_site! end |
.find_for_host(host) ⇒ Object
70 71 72 73 74 75 |
# File 'app/models/alchemy/site.rb', line 70 def find_for_host(host) # These are split up into two separate queries in order to run the # fastest query first (selecting the domain by its primary host name). # find_by(host: host) || find_in_aliases(host) || default end |
.find_in_aliases(host) ⇒ Object
77 78 79 80 81 82 83 |
# File 'app/models/alchemy/site.rb', line 77 def find_in_aliases(host) return nil if host.blank? all.find do |site| site.aliases.split.include?(host) if site.aliases.present? end end |
Instance Method Details
#current? ⇒ Boolean
Returns true if this site is the current site
35 36 37 |
# File 'app/models/alchemy/site.rb', line 35 def current? self.class.current == self end |
#default_language ⇒ Object
The default language for this site
There can only be one default language per site.
53 54 55 |
# File 'app/models/alchemy/site.rb', line 53 def default_language languages.find_by(default: true) end |
#to_partial_path ⇒ Object
Returns the path to site’s view partial.
Site view partials live in app/views/alchemy/site_layouts
Please use rails g alchemy:site_layouts
to generate partials for all your sites.
45 46 47 |
# File 'app/models/alchemy/site.rb', line 45 def to_partial_path "alchemy/site_layouts/#{partial_name}" end |