Class: Alchemy::Site
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- 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=(v) ⇒ 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
Class Method Details
.current ⇒ Object
60 61 62 |
# File 'app/models/alchemy/site.rb', line 60 def current RequestStore.store[:alchemy_current_site] || default end |
.current=(v) ⇒ Object
56 57 58 |
# File 'app/models/alchemy/site.rb', line 56 def current=(v) RequestStore.store[:alchemy_current_site] = v end |
.default ⇒ Object
64 65 66 |
# File 'app/models/alchemy/site.rb', line 64 def default Site.first end |
.find_for_host(host) ⇒ Object
68 69 70 71 72 73 |
# File 'app/models/alchemy/site.rb', line 68 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
75 76 77 78 79 80 81 |
# File 'app/models/alchemy/site.rb', line 75 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
33 34 35 |
# File 'app/models/alchemy/site.rb', line 33 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.
51 52 53 |
# File 'app/models/alchemy/site.rb', line 51 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.
43 44 45 |
# File 'app/models/alchemy/site.rb', line 43 def to_partial_path "alchemy/site_layouts/#{partial_name}" end |