Ruby on Rails中的自定义动态错误页面无法正常工作

时间:2010-05-26 16:02:46

标签: ruby-on-rails

我正在尝试在此帖子后面实现自定义动态错误页面: http://www.perfectline.co.uk/blog/custom-dynamic-error-pages-in-ruby-on-rails

我完全按照博文的说法做了。我在environment.rb中包含了config.action_controller.consider_all_requests_local = false。但是没有用。

我的浏览器显示:

Routing Error
No route matches "/555" with {:method=>:get}

所以,似乎没有解雇救援。 我在日志文件中得到以下内容:

ActionController::RoutingError (No route matches "/555" with {:method=>:get}):
Rendering rescues/layout (not_found)

是否存在一些干扰代码的路由?我不知道该找什么。我正在运行rails 2.3.5。

这是routes.rb文件:

ActionController::Routing::Routes.draw do |map|

  # routing van property-url
  map.connect 'buy/:property_type_plural/:province/:city/:address/:house_number', :controller => 'properties' , :action => 'show', :id => 'whatever'
  map.myimmonatie 'myimmonatie' , :controller => 'myimmonatie/properties', :action => 'index'
  map.login "login", :controller => "user_sessions", :action => "create", :conditions => {:method => :post}
  map.login "login", :controller => "user_sessions", :action => "new"
  map.logout "logout", :controller => "user_sessions", :action => "destroy"
  map.buy "buy", :controller => 'buy'
  map.sell "sell", :controller => 'sell'
  map.home "home", :controller => 'home'
  map.disclaimer "disclaimer", :controller => 'disclaimer'
  map.sign_up "sign_up", :controller => 'users', :action => :new
  map.contact "contact", :controller => 'contact'
  map.resources :user_sessions
  map.resources :contact
  map.resources :password_resets
  map.resources :messages
  map.resources :users, :only => [:index,:new,:create,:activate,:edit,:profile,:password]
  map.resources :images
  map.resources :activation , :only => [:new,:resend]
  map.resources :email
  map.resources :properties, :except => [:index,:destroy]

  map.namespace :admin do |admin|
       admin.resources :users
       admin.resources :properties
       admin.resources :order_items, :as => :orders
       admin.resources :blog_posts, :as => :blog
     end

     map.connect 'myimmonatie/:action' , :controller => 'users', :id => 'current', :requirements => {:action => /(profile)|(password)|(email)/}
     map.namespace :myimmonatie do |myimmonatie|
       myimmonatie.resources :messages, :controller => 'messages'
       myimmonatie.resources :password, :as => "password", :controller => 'users', :action => 'password'
       myimmonatie.resources :properties , :controller => 'properties'
       myimmonatie.resources :orders , :only => [:index,:show,:create,:new]
     end

  map.root :controller => "home"
  map.connect ':controller/:action'
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'

end

ActionController::Routing::Translator.translate_from_file('config','i18n-routes.yml')

2 个答案:

答案 0 :(得分:0)

代码有效,我的环境中的行有问题.rb config.action_controller.consider_all_requests_local = false 它似乎在某个地方被覆盖了。

所以,CASE CLOSED,谢谢!

答案 1 :(得分:0)

Rails会检测您何时使用ip 127.0.0.1进行浏览,并且即使您处于生产环境中也会显示开发环境错误。您应该尝试从其他计算机访问以获得正确的错误。