Rails没有路线匹配{:controller =>“devise / products”} [英] Rails No route matches {:controller=>"devise/products"}

查看:144
本文介绍了Rails没有路线匹配{:controller =>“devise / products”}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 

当我尝试登录或注册(我使用Devise GEM登录)时,我的rails应用程序出现以下错误。 code>路由错误
没有路由匹配{:controller =>devise / products}

应用程序的所有源代码可以在这里找到: https://github.com/rossmc/



我试过在 application.html.erb中更改 link_to / strong>& product / index.html.erb from:

 <%= link_to'登录' new_user_session_path%> 

to:

 code><%= link_to'登录',:controller => / products,new_user_session_path%> ;. 

但这只会引起更多错误。



<有趣的是,登录功能和我添加了部分购物车之前,路线正常工作,我最后一次提交时放在 application.html.erb 中。当我删除这个部分时,路由错误消失,但是我松开了我的部分 views / cart / _cart.html.erb



下面是控制台当我尝试登录并从运行rake routes命令。
提前感谢您抽出时间来看看。



控制台转储

 连接到database.yml指定的数据库
DEPRECATION警告:将块传递给devise_for已被弃用。请从devise_for中删除该块(只有块,对devise_for的调用仍然存在),并调用devise_scope:user do ...以块代替。 (C#/ Users / Ross / Documents / NCI-HDip /服务器端/ PROJ - 服务器端/ site / config / routes.rb:16)中的< top(required)>中的块)


在2012-12-02 22:15:33 +0000
启动GET/ users / sign_upfor Devise :: RegistrationsController#new as HTML
渲染C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/shared/_links.erb(2.0ms)
渲染C: /RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/registrations/new.html.erb在布局/应用程序(106.0ms)
[1m [36m产品负载(0.0ms)[0m [1mSELECT DISTINCT product_type FROMproducts[0m
Rendered products / _product_typeDistinctList.html(54.0ms)
渲染的购物车/ _cart.html.erb(91.0ms )
完成834ms内部服务器错误

ActionController :: RoutingError(无路由匹配{:controller =>devise / products}):
app / views / cart / _cart.html.erb:49:在`_app_views_cart__cart_html_er b__355880610_32436408'
app / views / layouts / application.html.erb:53:在`_app_views_layouts_application_html_erb__478801204_33653088'


渲染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在救援/布局(1.0ms)


启动GET / cart / 3为127.0.0.1在2012-12-02 22:15:39 +0000
处理CartController#添加为HTML
参数:{id=>3}
完成401未授权在1ms


启动GET/ users / sign_in为127.0.0.1在2012-12-02 22:15:39 +0000
处理由Devise :: SessionsController#new作为HTML
渲染C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/shared/ _links.erb(1.0ms)
渲染C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/sessions/new.html .erb in layouts / application(11.0ms)
[1m [35mProduct Load(0.0ms) [0m SELECT DISTINCT product_type FROMproducts
渲染产品/ _product_typeDistinctList.html(1.0ms)
渲染购物车/ _cart.html.erb(4.0ms)
在54ms内完成500内部服务器错误

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:在`_app_views_layouts_application_html_erb__478801204_33653088'


渲染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在救援/布局(1.0ms)


启动GET / users / sign_in为127.0.0.1在2012-12-02 22:15:43 +0000
处理由Devise :: SessionsController#new为HTML
渲染C:/RailsInstaller/Ruby1.9.3/ lib / ruby​​ / gems / 1.9.1 / gems / devise-2.1.2 / app / views / devise / shared / _links.erb(1.0ms)
渲染在布局/应用程序(9.0ms)中编辑C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-2.1.2/app/views/devise/sessions/new.html.erb
[1m [36m产品负载(0.0ms)[0m [1mSELECT DISTINCT product_type FROMproducts[0m
渲染产品/ _product_typeDistinctList.html(1.0ms)
渲染购物车/ _cart.html.erb (4.0ms)
51ms内完成500内部服务器错误

ActionController :: RoutingError(无路由匹配{:controller =>devise / products}):
应用/views/cart/_cart.html.erb:49:in`_app_views_cart__cart_html_erb__355880610_32436408'
app / views / layouts / application.html.erb:53:在`_app_views_layouts_application_html_erb__478801204_33653088'


在拯救/布局(0.0ms)内渲染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

耙路线

  C:\User s \Ross\Documents\NCI-HDip\Server Side\PROJ  - 服务器端端口> rake路由
配置文件GET /profiles(.:format)配置文件#index
POST /个人资料(。:format)个人资料#创建
new_profile GET /profiles/new(.:format)个人资料#new
edit_profile GET /profiles/:id/edit(.:format)个人资料#编辑
profile GET /profiles/:id(.:format)个人资料#show
PUT /profiles/:id(.:format)个人资料#update
DELETE /profiles/:id(.:format) profile#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(.:格式)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 / o rders /: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)设计/注册#取消
user_registration POST /users(.:format)设计/注册#create
new_user_registration GET / users / sign_up(。 :格式)设计/注册#新
edit_user_registration GET /users/edit(.:format)设计/注册#编辑
PUT /users(.:format)设计/注册#update
DELETE产品名称:$ / $ / $ / $ / $商品名称:产品/新(。:格式)产品#新
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(。 :格式)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)个人资料#myprofile
root / site#home


解决方案

仔细查看堆栈跟踪:

 开始GET/ users / sign_up为127.0.0.1在2012-12-02 18:47:23 -0500 
处理由Devise :: RegistrationsController#new作为HTML
渲染/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)
渲染/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在布局/应用程序中(2.3ms)
渲染产品/ _search.html.erb(0.3ms)
产品加载(0.1ms)SELECT DISTINCT product_type FROMproducts
渲染产品/ _product_typeDistinctList.html(0.5ms)
渲染cart / _cart.html.erb(0.7ms)
在14ms内完成500内部服务器错误

ActionController :: RoutingError(无路由匹配{: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:在`_app_views_layouts_application_html_erb___2170720560050181211_22251920'


渲染/首页/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在救援/布局( 0.5ms)

找到了吗?日志显示它已经渲染了一些部分,直到 cart / _cart.html.erb 。它甚至告诉你错误发生在第49行。现在第49行是什么?这是:

 <%= link_to'保持购物',:controller => :产品%> 
<%= link_to'Empty Cart',:controller => cart,:action => clearCart%>
<%= link_to'继续检出',:controller => cart,:action => createOrder%>

正如Ryan在以下评论,Rails正在寻找 Devise 因为这是你正在渲染的那个。



更简单的说,你可以提供它的路由名称(你将在 rake路线),您可以向帮助者添加 _path 以形成URL。 products_path 最终成为 products#index 的URL字符串。



在您的情况下

 <%= link_to保持购物,products_path%> 
<%= link_to'清空购物车',clearCart_path%>
<%= link_to'继续检出',checkout_path%>

听你的堆栈跟踪,他们正在和你说话!


I get the below error on my rails application when I try to login or register (I'm using the Devise GEM for logins).

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

All the source code for the application can be found here: https://github.com/rossmc/topsnowboards

I've tried changing the link_to in application.html.erb & product/index.html.erb from:

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

to:

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

But this just throw up more errors.

Interestingly the login features & routes were working fine before I added a partial for the shopping cart, which I placed in the application.html.erb on my last commit. When I remove this partial the routing error disappears but I loose my partial views/cart/_cart.html.erb.

Below is the console dump from when I try to login & run the rake routes command. Thanks in advance for taking the time to look at this.

Console Dump

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)

rake routes

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

解决方案

Look more closely at your stack trace:

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)

Found it? The log shows it has rendered a bunch of partials, down to cart/_cart.html.erb. It even tells you the error happens on line 49. Now what's on line 49? This:

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

As Ryan rightly points out in the following comment, Rails is looking for a partial scoped under Devise since this is the one under which you're rendering.

More simply, you can just feed it the route name (the one you'll find in rake routes) to which you add _path for a helper to form a URL. products_path ends up being the URL string for products#index.

Which gives in your case

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

Listen to your stack traces, they're talking to you!

这篇关于Rails没有路线匹配{:controller =&gt;“devise / products”}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆