Permalink
Browse files

building the right url for pages taking care of site path #173

  • Loading branch information...
1 parent 2332f02 commit 5ff25071ba96abe542171ed61fb23e7c9e2b784b @danimashu danimashu committed Apr 12, 2012
@@ -60,7 +60,7 @@ def load_cms_site
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
+ return redirect_to(@cms_page.target_page.url) if @cms_page.target_page
rescue ActiveRecord::RecordNotFound
if @cms_page = @cms_site.pages.published.find_by_full_path('/404')
@@ -63,7 +63,8 @@ def self.options_for_select(site, page = nil, current_page = nil, depth = 0, exc
end
# -- Instance Methods -----------------------------------------------------
- # For previewing purposes sometimes we need to have full_path set
+ # For previewing purposes sometimes we need to have full_path set. This
+ # full path take care of the pages and its childs but not of the site path
def full_path
self.read_attribute(:full_path) || self.assign_full_path
end
@@ -122,7 +123,7 @@ def tags(force_reload = false)
# Full url for a page
def url
- "http://#{self.site.hostname}#{self.full_path}"
+ "http://" + "#{self.site.hostname}/#{self.site.path}/#{self.full_path}".squeeze("/")
end
# Method to collect prevous state of blocks for revisions
@@ -4,3 +4,10 @@ default:
hostname: test.host
path:
is_mirrored: false
+
+with_path:
+ label: With Path Site
+ identifier: with-path-site
+ hostname: test.host
+ path: /en/site
+ is_mirrored: false
@@ -207,6 +207,12 @@ def test_root?
def test_url
assert_equal 'http://test.host/', cms_pages(:default).url
assert_equal 'http://test.host/child-page', cms_pages(:child).url
+
+ page = cms_sites(:with_path).pages.create!(new_params)
+ assert_equal 'http://test.host/en/site/', page.url
+
+ child_page = cms_sites(:with_path).pages.create!(new_params(:parent => page))
+ assert_equal 'http://test.host/en/site/test-page', child_page.url
end
def test_unicode_slug_escaping

0 comments on commit 5ff2507

Please sign in to comment.