簡體   English   中英

Rails沒有路由匹配{:controller =>“devise / products”}

[英]Rails No route matches {:controller=>“devise/products”}

當我嘗試登錄或注冊時,我在rails應用程序上收到以下錯誤(我正在使用Devise GEM進行登錄)。

Routing Error
No route matches {:controller=>"devise/products"}

可以在此處找到應用程序的所有源代碼: https//github.com/rossmc/topsnowboards

我嘗試更改application.html.erbproduct / index.html.erb中link_to

<%= link_to 'sign in', new_user_session_path  %>

至:

<%= link_to 'sign in', :controller => "/products", new_user_session_path %>. 

但這只會引發更多錯誤。

有趣的是,在我添加購物車的部分之前,登錄功能和路由工作正常,我在上次提交時將其放在application.html.erb中 當我刪除此部分時,路由錯誤消失,但我丟失了部分視圖/ cart / _cart.html.erb

下面是我嘗試登錄並運行rake routes命令時的控制台轉儲。 提前感謝您抽出時間來看看這個。

控制台轉儲

Connecting to database specified by database.yml
DEPRECATION WARNING: Passing a block to devise_for is deprecated. Please remove the block from devise_for (only the block, the call to devise_for must still exist) and call devise_scope :user do ... end with the block instead. (called from block in <top (required)> at C:/Users/Ross/Documents/NCI-HDip/Server Side/PROJ - Server Side/site/config/routes.rb:16)


Started GET "/users/sign_up" for 127.0.0.1 at 2012-12-02 22:15:33 +0000
Processing by Devise::RegistrationsController#new as HTML
  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/shared/_links.erb (2.0ms)
  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/registrations/new.html.erb within layouts/application (106.0ms)
  [1m[36mProduct Load (0.0ms)[0m  [1mSELECT DISTINCT product_type FROM "products" [0m
  Rendered products/_product_typeDistinctList.html (54.0ms)
  Rendered cart/_cart.html.erb (91.0ms)
Completed 500 Internal Server Error in 834ms

ActionController::RoutingError (No route matches {:controller=>"devise/products"}):
  app/views/cart/_cart.html.erb:49:in `_app_views_cart__cart_html_erb__355880610_32436408'
  app/views/layouts/application.html.erb:53:in `_app_views_layouts_application_html_erb__478801204_33653088'


  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)


Started GET "/cart/3" for 127.0.0.1 at 2012-12-02 22:15:39 +0000
Processing by CartController#add as HTML
  Parameters: {"id"=>"3"}
Completed 401 Unauthorized in 1ms


Started GET "/users/sign_in" for 127.0.0.1 at 2012-12-02 22:15:39 +0000
Processing by Devise::SessionsController#new as HTML
  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/shared/_links.erb (1.0ms)
  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/sessions/new.html.erb within layouts/application (11.0ms)
  [1m[35mProduct Load (0.0ms)[0m  SELECT DISTINCT product_type FROM "products" 
  Rendered products/_product_typeDistinctList.html (1.0ms)
  Rendered cart/_cart.html.erb (4.0ms)
Completed 500 Internal Server Error in 54ms

ActionController::RoutingError (No route matches {:controller=>"devise/products"}):
  app/views/cart/_cart.html.erb:49:in `_app_views_cart__cart_html_erb__355880610_32436408'
  app/views/layouts/application.html.erb:53:in `_app_views_layouts_application_html_erb__478801204_33653088'


  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)


Started GET "/users/sign_in" for 127.0.0.1 at 2012-12-02 22:15:43 +0000
Processing by Devise::SessionsController#new as HTML
  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/shared/_links.erb (1.0ms)
  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/sessions/new.html.erb within layouts/application (9.0ms)
  [1m[36mProduct Load (0.0ms)[0m  [1mSELECT DISTINCT product_type FROM "products" [0m
  Rendered products/_product_typeDistinctList.html (1.0ms)
  Rendered cart/_cart.html.erb (4.0ms)
Completed 500 Internal Server Error in 51ms

ActionController::RoutingError (No route matches {:controller=>"devise/products"}):
  app/views/cart/_cart.html.erb:49:in `_app_views_cart__cart_html_erb__355880610_32436408'
  app/views/layouts/application.html.erb:53:in `_app_views_layouts_application_html_erb__478801204_33653088'


  Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.0ms)

耙路線

C:\Users\Ross\Documents\NCI-HDip\Server Side\PROJ - Server Side\site>rake routes
                profiles GET    /profiles(.:format)                            profiles#index
                         POST   /profiles(.:format)                            profiles#create
             new_profile GET    /profiles/new(.:format)                        profiles#new
            edit_profile GET    /profiles/:id/edit(.:format)                   profiles#edit
                 profile GET    /profiles/:id(.:format)                        profiles#show
                         PUT    /profiles/:id(.:format)                        profiles#update
                         DELETE /profiles/:id(.:format)                        profiles#destroy
         lineitems_index GET    /lineitems/index(.:format)                     lineitems#index
          lineitems_show GET    /lineitems/show(.:format)                      lineitems#show
           lineitems_new GET    /lineitems/new(.:format)                       lineitems#new
          lineitems_edit GET    /lineitems/edit(.:format)                      lineitems#edit
         order_lineitems GET    /orders/:order_id/lineitems(.:format)          lineitems#index
                         POST   /orders/:order_id/lineitems(.:format)          lineitems#create
      new_order_lineitem GET    /orders/:order_id/lineitems/new(.:format)      lineitems#new
     edit_order_lineitem GET    /orders/:order_id/lineitems/:id/edit(.:format) lineitems#edit
          order_lineitem GET    /orders/:order_id/lineitems/:id(.:format)      lineitems#show
                         PUT    /orders/:order_id/lineitems/:id(.:format)      lineitems#update
                         DELETE /orders/:order_id/lineitems/:id(.:format)      lineitems#destroy
                  orders GET    /orders(.:format)                              orders#index
                         POST   /orders(.:format)                              orders#create
               new_order GET    /orders/new(.:format)                          orders#new
              edit_order GET    /orders/:id/edit(.:format)                     orders#edit
                   order GET    /orders/:id(.:format)                          orders#show
                         PUT    /orders/:id(.:format)                          orders#update
                         DELETE /orders/:id(.:format)                          orders#destroy
                         GET    /orders(.:format)                              orders#index
                         POST   /orders(.:format)                              orders#create
                         GET    /orders/new(.:format)                          orders#new
                         GET    /orders/:id/edit(.:format)                     orders#edit
                         GET    /orders/:id(.:format)                          orders#show
                         PUT    /orders/:id(.:format)                          orders#update
                         DELETE /orders/:id(.:format)                          orders#destroy
        new_user_session GET    /users/sign_in(.:format)                       devise/sessions#new
            user_session POST   /users/sign_in(.:format)                       devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)                      devise/sessions#destroy
           user_password POST   /users/password(.:format)                      devise/passwords#create
       new_user_password GET    /users/password/new(.:format)                  devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)                 devise/passwords#edit
                         PUT    /users/password(.:format)                      devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                        devise/registrations#cancel
       user_registration POST   /users(.:format)                               devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)                       devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                          devise/registrations#edit
                         PUT    /users(.:format)                               devise/registrations#update
                         DELETE /users(.:format)                               devise/registrations#destroy
                products GET    /products(.:format)                            products#index
                         POST   /products(.:format)                            products#create
             new_product GET    /products/new(.:format)                        products#new
            edit_product GET    /products/:id/edit(.:format)                   products#edit
                 product GET    /products/:id(.:format)                        products#show
                         PUT    /products/:id(.:format)                        products#update
                         DELETE /products/:id(.:format)                        products#destroy
              cart_index GET    /cart/index(.:format)                          cart#index
               site_home GET    /site/home(.:format)                           site#home
               site_shop GET    /site/shop(.:format)                           site#shop
              site_guide GET    /site/guide(.:format)                          site#guide
              site_links GET    /site/links(.:format)                          site#links
            site_contact GET    /site/contact(.:format)                        site#contact
                    cart        /cart(.:format)                                cart#index
                                /cart/:id(.:format)                            cart#add
                                /cart/remove/:id(.:format)                     cart#remove
               clearCart        /clearCart(.:format)                           cart#clearCart
                    home        /home(.:format)                                site#home
                    shop        /shop(.:format)                                products#index
                   guide        /guide(.:format)                               site#guide
                   links        /links(.:format)                               site#links
                 contact        /contact(.:format)                             site#contact
                checkout        /checkout(.:format)                            cart#createOrder
                                /product_type/:id(.:format)                    products#product_type
               myprofile        /myprofile(.:format)                           profiles#myprofile
                    root        /                                              site#home

仔細查看堆棧跟蹤:

Started GET "/users/sign_up" for 127.0.0.1 at 2012-12-02 18:47:23 -0500
Processing by Devise::RegistrationsController#new as HTML
  Rendered /home/jon/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/shared/_links.erb (0.3ms)
  Rendered /home/jon/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/registrations/new.html.erb within layouts/application (2.3ms)
  Rendered products/_search.html.erb (0.3ms)
  Product Load (0.1ms)  SELECT DISTINCT product_type FROM "products" 
  Rendered products/_product_typeDistinctList.html (0.5ms)
  Rendered cart/_cart.html.erb (0.7ms)
Completed 500 Internal Server Error in 14ms

ActionController::RoutingError (No route matches {:controller=>"devise/products"}):
  app/views/cart/_cart.html.erb:49:in `_app_views_cart__cart_html_erb___3785130162884562793_21827300'
  app/views/layouts/application.html.erb:59:in `_app_views_layouts_application_html_erb___2170720560050181211_22251920'


  Rendered /home/jon/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.5ms)

找到了? 日志顯示它已經呈現了一堆部分,一直到cart/_cart.html.erb 它甚至告訴你錯誤發生在第49行。現在第49行是什么? 這個:

<%= link_to 'Keep Shopping', :controller => :products %>
<%= link_to 'Empty Cart', :controller => "cart", :action => "clearCart" %>
<%= link_to 'Proceed to Check Out', :controller => "cart", :action => "createOrder" %>

正如Ryan在下面的評論中正確指出的那樣,Rails正在尋找Devise下的部分范圍,因為這是你正在渲染的那個。

更簡單地說,您可以只為其添加路徑名稱(您在rake routes找到的路徑名稱),並為其添加_path以形成URL。 products_path最終成為products#index的URL字符串。

在你的情況下給出了

<%= link_to 'Keep Shopping', products_path %>
<%= link_to 'Empty Cart', clearCart_path %>
<%= link_to 'Proceed to Check Out', checkout_path %>

聽聽你的堆棧痕跡,他們正在跟你說話!

方式來晚了,但這是我的解決方案。 只需在控制器前加上“ / ”作為絕對值。 有點長而丑,但返回控制器/動作或傳遞路線的鏈接。 我用它來構建從sql表驅動的菜單。

  # dynamic link_to
  def menu_link(params, html_options=nil)
    if params[:controller].present?
      link_to params[:display], {controller: "/#{params[:controller]}", action: params[:resource]}, default_navigation_options(html_options)
    elsif params[:route].present?
      link_to params[:display], params[:route], default_navigation_options(html_options)
    end
  end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM