我们有一个 Rails 应用程序,它不断产生我们无法追踪的错误。问题似乎出在路由上,但我们不确定发生了什么。输出路由文件如下所示:
ActionController::Routing::Routes.draw do |map|
# Default
map.home '', :controller => "home"
# Admin
map.admin_home 'admin', :controller => 'admin/admin', :action => 'index'
map.admin_login 'admin/login', :controller => 'admin/admin', :action => 'login'
map.admin_reminder 'admin/forgot', :controller => 'admin/admin', :action => 'reminder'
map.namespace :admin do |admin|
admin.resources :bookings,
:collection => {
:archive => :get, :reports => :get, :calendar => :get,
:step_1 => :any, :step_1a => :any, :step_2 => :any, :step_3 => :any, :confirmation => :any }
admin.resources :events,
:member => { :status => :get }
admin.resources :blogs,
:collection => { :archive => :get }
admin.resources :blog_replies,
:member => { :publish => :get }
admin.resources :minutes,
:collection => { :archive => :get }
admin.resources :businesses
admin.resources :business_categories
admin.resources :users
admin.resources :pricings
admin.backups 'backups', :controller => 'admin/backups'
admin.download_backup 'backups/download', :controller => 'admin/backups', :action => 'download'
end
map.admin 'admin/:action', :controller => 'admin/admin'
map.connect 'members', :controller => 'admin/admin', :action => 'redirect_to_index'
map.connect 'members/login', :controller => 'admin/admin', :action => 'redirect_to_index'
map.connect 'account', :controller => 'admin/admin', :action => 'redirect_to_index'
map.connect 'account/login', :controller => 'admin/admin', :action => 'redirect_to_index'
map.connect 'home', :controller => 'admin/admin', :action => 'redirect_to_index'
map.connect 'home/login', :controller => 'admin/admin', :action => 'redirect_to_index'
map.blog 'blog/:permalink', :controller => 'blogs', :action => 'show'
map.connect 'blog/:id', :controller => 'blogs', :action => 'show'
map.connect 'book-online', :controller => 'bookings', :action => 'step_1'
map.connect 'book-online/:action', :controller => 'bookings'
# Defaults
map.connect ':controller/:action/:id'
map.connect "*anything", :controller => "public", :action => "unknown_request"
end
我们在 app/controllers 中有一组公共控制器,在 app/controllers/admin 中有一组管理控制器。我们一直看到的问题是,当用户访问诸如 admin/bookings、admin/bookings/step_1 或 admin/events 之类的 URL 时。有时 url 工作得很好,但有时我可以从日志文件中看到类似以下的事情发生:
ActionController::UnknownAction (No action responded to index):
其他时候我们会得到类似的东西:
Processing EventsController#index (for [filtered] at 2009-01-21 10:54:38) [GET]
Session ID: [filtered]
Parameters: {"action"=>"index", "controller"=>"admin/events"}
Rendering template within layouts/public
Rendering events/index
Completed in 0.00863 (115 reqs/sec) | Rendering: 0.00338 (39%) | DB: 0.00000 (0%) | 200 OK [http://www.gresfordtrust.org/admin/events]
从最后一个示例中,您可以看到请求的 urladmin/events
应该已经点击了#index
in ,Admin::EventsController
但它呈现了in 中的#index
操作EventsController
。
我们正在使用 Rails 2.0.2 运行该应用程序。