stating with i18n, need to think how to quickly load proper site

Oleg committed Jun 07, 2011
commit 9cbbbc84485cf5a02974eaaef8d1f67f22f7f2c0
Showing 5 changed files with 33 additions and 8 deletions
app/controllers/cms_content_controller.rb +5 -5
@@ @@ -26,11 +26,6 @@ class CmsContentController < ApplicationController
protected
- def load_fixtures
- return unless ComfortableMexicanSofa.config.enable_fixtures
- ComfortableMexicanSofa::Fixtures.import_all(@cms_site.hostname)
- end
-
def load_cms_site
@cms_site = if ComfortableMexicanSofa.config.enable_multiple_sites
Cms::Site.find_by_hostname(request.host.downcase)
@@ @@ -40,6 +35,11 @@ protected
render :text => 'Site Not Found', :status => 404 if !@cms_site
end
+ def load_fixtures
+ return unless ComfortableMexicanSofa.config.enable_fixtures
+ ComfortableMexicanSofa::Fixtures.import_all(@cms_site.hostname)
+ end
+
def load_cms_page
@cms_page = @cms_site.pages.published.find_by_full_path!("/#{params[:cms_path]}")
return redirect_to(@cms_page.target_page.full_path) if @cms_page.target_page
app/models/cms/site.rb +4 -1
@@ @@ -14,9 +14,12 @@ class Cms::Site < ActiveRecord::Base
# -- Validations ----------------------------------------------------------
validates :label,
:presence => true
+ validates :path,
+ :presence => true,
+ :format => { :with => /^\/[\w\d\-\/]+$/ }
validates :hostname,
:presence => true,
- :uniqueness => true,
+ :uniqueness => { :scope => :path },
:format => { :with => /^[\w\.\-]+$/ }
# -- Class Methods --------------------------------------------------------
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb +4 -1
@@ @@ -5,8 +5,11 @@ class CreateCms < ActiveRecord::Migration
create_table :cms_sites do |t|
t.string :label
t.string :hostname
+ t.string :path, :null => false, :default => '/'
+ t.boolean :is_mirrored, :null => false, :default => false
end
- add_index :cms_sites, :hostname
+ add_index :cms_sites, [:hostname, :path]
+ add_index :cms_sites, :is_mirrored
# -- Layouts ------------------------------------------------------------
create_table :cms_layouts do |t|
migrate/upgrades/04_upgrade_to_1_3_0.rb b/db/migrate/upgrades/04_upgrade_to_1_3_0.rb +17 -0
@@ @@ -0,0 +1,17 @@
+ class UpgradeTo130 < ActiveRecord::Migration
+ def self.up
+ add_column :cms_sites, :is_mirrored, :boolean, :null => false, :default => false
+ add_column :cms_sites, :path, :string, :null => false, :default => '/'
+ remove_index :cms_sites, :hostname
+ add_index :cms_sites, [:hostname, :path]
+ add_index :cms_sites, :is_mirrored
+ end
+
+ def self.down
+ remove_index :cms_sites, [:hostname, :path]
+ remove_index :cms_sites, :is_mirrored
+ add_index :cms_sites, :hostname
+ remove_column :cms_sites, :path
+ remove_column :cms_sites, :is_mirrored
+ end
+ end
\ No newline at end of file
test/fixtures/cms/sites.yml +3 -1
@@ @@ -1,3 +1,5 @@
default:
label: Default Site
- hostname: test.host
\ No newline at end of file
+ hostname: test.host
+ path: /
+ is_mirrored: false
\ No newline at end of file