0
我只是從Rails 3中的大型應用程序升級到Rails的3.1的中間,我的執行頁面控制器的敲了一個問題:的Rails 3.1和靜態頁面
when templates doesnt exist
should render the 404 page (FAILED - 1)
Failures:
1) PagesController automatic paths when templates doesnt exist should render the 404 page
Failure/Error: get 'base_page_processor', :base_page => 'something_that_doesnt_exist'
NoMethodError:
undefined method `map' for "pages":String
# ./app/controllers/pages_controller.rb:5:in `base_page_processor'
# ./spec/controllers/pages_controller_spec.rb:37:in `block (3 levels) in <top (required)>'
Finished in 0.10557 seconds
4 examples, 1 failure
Failed examples:
rspec ./spec/controllers/pages_controller_spec.rb:36 # PagesController automatic paths when templates doesnt exist should render the 404 page
這Rails有工作3.0。必須通過template_exists方法更改某些內容。這裏是控制器:
class PagesController < ApplicationController
def base_page_processor
view_prefix = "pages"
if params[:base_page].present? && template_exists?(params[:base_page], view_prefix)
render "#{view_prefix}/#{params[:base_page]}"
else
#TODO : Notify missing url via email error or error notification service
render '/public/404.html', :status => 404
end
end
end
解決方案代碼:
class PagesController < ApplicationController
def base_page_processor
view_prefix = ["pages"]
if params[:base_page].present? && template_exists?(params[:base_page], view_prefix)
render "#{view_prefix[0]}/#{params[:base_page]}"
else
#TODO : Notify missing url via email error or error notification service
render '/errors/404.html', :status => 404
end
end
end
我也注意到,它並沒有渲染錯誤的觀點(即:/public/404.html),所以我創建了一個應用程序目錄/ views/errors並把所有的錯誤靜態頁面放在那裏,現在就渲染它們。有用。
謝謝安德魯。