when page has no layout, let's not crash
Oleg
committed Apr 30, 2011
commit 5e8c7e533e63f7542abf5ae561ee1518c2ffcb8a
Showing 2
changed files with
14 additions
and 2 deletions
app/controllers/cms_content_controller.rb
+6
-2
| @@ | @@ -8,8 +8,12 @@ class CmsContentController < ApplicationController |
| caches_page :render_css, :render_js, :if => Proc.new { |c| ComfortableMexicanSofa.config.enable_caching } | |
| def render_html(status = 200) | |
| - | layout = @cms_page.layout.app_layout.blank?? false : @cms_page.layout.app_layout |
| - | render :inline => @cms_page.content, :layout => layout, :status => status |
| + | if layout = @cms_page.layout |
| + | app_layout = layout.app_layout.blank?? false : layout.app_layout |
| + | render :inline => @cms_page.content, :layout => app_layout, :status => status |
| + | else |
| + | render :text => 'Layout Not Found', :status => 404 |
| + | end |
| end | |
| def render_css | |
test/functional/cms_content_controller_test.rb
+8
-0
| @@ | @@ -60,6 +60,14 @@ class CmsContentControllerTest < ActionController::TestCase |
| assert_equal 'Site Not Found', response.body | |
| end | |
| + | def test_render_page_with_no_layout |
| + | Cms::Layout.destroy_all |
| + | |
| + | get :render_html, :cms_path => '' |
| + | assert_response 404 |
| + | assert_equal 'Layout Not Found', response.body |
| + | end |
| + | |
| def test_render_page_with_redirect | |
| cms_pages(:child).update_attribute(:target_page, cms_pages(:default)) | |
| assert_equal cms_pages(:default), cms_pages(:child).target_page | |