2011-04-05 46 views
0

我有完全相同的問題,因爲在這種威脅沒有路由匹配「/應用」與{:方法=>:得到}

http://railsforum.com/viewtopic.php?pid=139352#p139352

但不幸的是,在不指定解決方案...

我的SO是Ubuntu的10.10 我的Apache服務器集成在xampp1.7.4 的Rails 2.3.5

我得到的錯誤,當我在http://localhost:3000/application

ActionController::RoutingError (No route matches "/application" with {:method=>:get}): 
    /usr/lib/ruby/1.8/action_controller/routing/recognition_optimisation.rb:66:in `recognize_path' 
    /usr/lib/ruby/1.8/action_controller/routing/route_set.rb:441:in `recognize' 
    /usr/lib/ruby/1.8/action_controller/routing/route_set.rb:436:in `call' 
    /usr/lib/ruby/1.8/action_controller/dispatcher.rb:87:in `dispatch' 
    /usr/lib/ruby/1.8/action_controller/dispatcher.rb:121:in `_call' 
    /usr/lib/ruby/1.8/action_controller/dispatcher.rb:130:in `build_middleware_stack' 
    /usr/lib/ruby/1.8/active_record/query_cache.rb:29:in `call' 
    /usr/lib/ruby/1.8/active_record/query_cache.rb:29:in `call' 
    /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache' 
    /usr/lib/ruby/1.8/active_record/query_cache.rb:9:in `cache' 
    /usr/lib/ruby/1.8/active_record/query_cache.rb:28:in `call' 
    /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call' 
    /usr/lib/ruby/1.8/action_controller/string_coercion.rb:25:in `call' 
    /usr/lib/ruby/1.8/rack/head.rb:9:in `call' 
    /usr/lib/ruby/1.8/rack/methodoverride.rb:24:in `call' 
    /usr/lib/ruby/1.8/action_controller/params_parser.rb:15:in `call' 
    /usr/lib/ruby/1.8/action_controller/session/cookie_store.rb:93:in `call' 
    /usr/lib/ruby/1.8/action_controller/failsafe.rb:26:in `call' 
    /usr/lib/ruby/1.8/rack/lock.rb:11:in `call' 
    /usr/lib/ruby/1.8/rack/lock.rb:11:in `synchronize' 
    /usr/lib/ruby/1.8/rack/lock.rb:11:in `call' 
    /usr/lib/ruby/1.8/action_controller/dispatcher.rb:114:in `call' 
    /usr/lib/ruby/1.8/action_controller/reloader.rb:34:in `run' 
    /usr/lib/ruby/1.8/action_controller/dispatcher.rb:108:in `call' 
    /usr/lib/ruby/1.8/rack/urlmap.rb:47:in `call' 
    /usr/lib/ruby/1.8/rack/urlmap.rb:41:in `each' 
    /usr/lib/ruby/1.8/rack/urlmap.rb:41:in `call' 
    /usr/lib/ruby/1.8/rack/content_length.rb:13:in `call' 
    /usr/lib/ruby/1.8/rack/handler/webrick.rb:48:in `service' 
    /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' 
    /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' 
    /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' 
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start' 
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' 
    /usr/lib/ruby/1.8/webrick/server.rb:95:in `start' 
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `each' 
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `start' 
    /usr/lib/ruby/1.8/webrick/server.rb:23:in `start' 
    /usr/lib/ruby/1.8/webrick/server.rb:82:in `start' 
    /usr/lib/ruby/1.8/rack/handler/webrick.rb:14:in `run' 

編輯 route.rb

ActionController::Routing::Routes.draw do |map| 
    # The priority is based upon order of creation: first created -> highest priority. 

    # Sample of regular route: 
    # map.connect 'products/:id', :controller => 'catalog', :action => 'view' 
    # Keep in mind you can assign values other than :controller and :action 

    # Sample of named route: 
    # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' 
    # This route can be invoked with purchase_url(:id => product.id) 

    # Sample resource route (maps HTTP verbs to controller actions automatically): 
    # map.resources :products 

    # Sample resource route with options: 
    # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } 

    # Sample resource route with sub-resources: 
    # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller 

    # Sample resource route with more complex sub-resources 
    # map.resources :products do |products| 
    #  products.resources :comments 
    #  products.resources :sales, :collection => { :recent => :get } 
    # end 

    # Sample resource route within a namespace: 
    # map.namespace :admin do |admin| 
    #  # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) 
    #  admin.resources :products 
    # end 

    # You can have the root of your site routed with map.root -- just remember to delete public/index.html. 
    # map.root :controller => "welcome" 

    # See how all your routes lay out with "rake routes" 

    # Install the default routes as the lowest priority. 
    # Note: These default routes make all actions in every controller accessible via GET requests. You should 
    # consider removing or commenting them out if you're using named routes and resources. 
    map.connect ':controller/:action/:id' 
    map.connect ':controller/:action/:id.:format' 
end 

在此先感謝!

+0

發表您的routes文件 – 2011-04-05 19:30:21

+0

我編輯我的問題,謝謝 – 2011-04-05 19:36:36

+0

路線@ BlancaHdez該鏈接不會有任何問題(至少在您未登錄該網站時)。不知道問題的背景是什麼。 – mattLummus 2016-08-03 19:40:37

回答

2

你的問題正是錯誤轉儲所說的。你只映射了兩件東西,它們都不匹配/application

map.connect ':controller/:action/:id' 
    map.connect ':controller/:action/:id.:format' 

將只匹配之類的東西

`/posts/show/1` 
    `/pages/edit/4.html` 

您需要添加這將指向行動的ApplicationController

+0

應該指出,不鼓勵直接路由到ApplicationController。由於它經常用作「類似於幫助器」的方法(current_user等)的存儲庫,因此可能會非常容易地意外暴露出您不想要的內容。 – bioneuralnet 2011-04-05 19:44:18

+0

對不起,我不太瞭解routes.rb是如何構建的,以及如何使用它。我找到了幾個教程,但沒有一個很清楚。有人能告訴我一個好的嗎?謝謝 – 2011-04-05 20:00:30

+1

http://edgeguides.rubyonrails.org/routing.html – 2011-04-05 20:01:23

相關問題