简体   繁体   English

Rails设计路由错误 - “无路由匹配”(controller =>“devise / sessions”)

[英]Rails Devise routing error - “No route matches” (controller=>“devise/sessions”)

Edit 2: Looks like a quick temp fix for me was to add a forward slash "/" in front of the controller name in my link_to_unless_current and current_page methods from my view. 编辑2:对我来说,快速临时修复似乎是在我的视图中的link_to_unless_current和current_page方法中在控制器名称前添加正斜杠“/”。 eg 例如

<% active = current_page?(:controller => '/sites', :action => action) ? 'active' : '' %>
      <li class="<%= active %>"><%= link_to_unless_current(anchor, { :controller => '/sites', :action => action }) %></li>

Here is more info on the problem I encountered in case anyone else runs into the same thing. 这里有更多关于我遇到的问题的信息,以防其他人遇到同样的事情。 https://github.com/plataformatec/devise/issues/471 https://github.com/plataformatec/devise/issues/471

============================================================ ================================================== ==========

My devise path broke when I made my navigation (_header.html.erb) dynamic. 当我的导航(_header.html.erb)动态时,我的设计路径破裂了。 I'm hoping this is a simple fix, but really lost atm. 我希望这是一个简单的修复,但真的失去了atm。 Every page on my site works, except when I go to /admin and then I get the routing error below: 我的网站上的每个页面都有效,除非我去/ admin,然后我收到以下路由错误:

Here's the exact error I receive: 这是我收到的确切错误:

Started GET "/admin" for 75.13.95.55 at 2011-03-13 15:40:49 -0500
  Processing by AdminController#index as HTML
Completed   in 2ms


Started GET "/users/sign_in" for 75.13.95.55 at 2011-03-13 15:40:51 -0500
  Processing by Devise::SessionsController#new as HTML
Rendered /usr/local/rvm/gems/ruby-1.9.2-p0/gems/devise-1.1.5/app/views/devise/shared/_links.erb (1.9ms)
Rendered layouts/_header.html.erb (37.0ms)
Rendered /usr/local/rvm/gems/ruby-1.9.2-p0/gems/devise-1.1.5/app/views/devise/sessions/new.html.erb within layouts/application (57.5ms)
Completed   in 91ms

ActionView::Template::Error (No route matches {:action=>"coupons", :controller=>"devise/sessions"}):
    7: <div id="navcontainer">
    8:   <ul id="navlist">
    9:     <% nav.each do |anchor, action| %>
    10:       <% active = current_page?(:action => action) ? 'active' : '' %>
    11:       <li class="<%= active %>"><%= link_to_unless_current(anchor, { :action => action }) %></li>
    12:     <% end -%>
    13:   </ul>
  app/views/layouts/_header.html.erb:10:in `block in _app_views_layouts__header_html_erb__482084855_91994390_872614734'
  app/views/layouts/_header.html.erb:9:in `each'
  app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__482084855_91994390_872614734'
  app/views/layouts/application.html.erb:17:in `_app_views_layouts_application_html_erb___293959382_92160660__194406143'

Here is the config/routes.rb file: 这是config/routes.rb文件:

  devise_for :users

  match '/info' => 'sites#info', :as => :info
  match "/reviews" => 'sites#reviews', :as => :reviews

  resources :admin do
    collection do
      put 'moderate'
      get 'approved'
    end
  end

  root :to => 'sites#coupons'

Here's the app/views/layouts/_header.html.erb file: 这是app/views/layouts/_header.html.erb文件:

<% nav = { 'Coupons' => 'coupons', 'Reviews' => 'reviews', 'Info' => 'info' } %>

<div id="navcontainer">
  <ul id="navlist">
    <% nav.each do |anchor, action| %>
      <% active = current_page?(:action => action) ? 'active' : '' %>
      <li class="<%= active %>"><%= link_to_unless_current(anchor, { :action => action }) %></li>
    <% end -%>

And here's the output of rake routes : 这是rake routes的输出:

      new_user_session GET    /users/sign_in(.:format)           {:action=>"new", :controller=>"devise/sessions"}
          user_session POST   /users/sign_in(.:format)           {:action=>"create", :controller=>"devise/sessions"}
  destroy_user_session GET    /users/sign_out(.:format)          {:action=>"destroy", :controller=>"devise/sessions"}
                  info        /info(.:format)                    {:controller=>"sites", :action=>"info"}
               reviews        /reviews(.:format)                 {:controller=>"sites", :action=>"reviews"}
moderate_admin_index PUT    /admin/moderate(.:format)        {:action=>"moderate", :controller=>"admin"}
approved_admin_index GET    /admin/approved(.:format)        {:action=>"approved", :controller=>"admin"}
         admin_index GET    /admin(.:format)                 {:action=>"index", :controller=>"admin"}
                       POST   /admin(.:format)                 {:action=>"create", :controller=>"admin"}
           new_admin GET    /admin/new(.:format)             {:action=>"new", :controller=>"admin"}
          edit_admin GET    /admin/:id/edit(.:format)        {:action=>"edit", :controller=>"admin"}
               admin GET    /admin/:id(.:format)             {:action=>"show", :controller=>"admin"}
                       PUT    /admin/:id(.:format)             {:action=>"update", :controller=>"admin"}
                       DELETE /admin/:id(.:format)             {:action=>"destroy", :controller=>"admin"}
                  root        /(.:format)                        {:controller=>"sites", :action=>"coupons"}

Thanks for looking! 谢谢你的期待!

Edit 1: When I tried the suggestion from @Dogbert, it didn't seem to make a difference unfortunately: 编辑1:当我尝试@Dogbert的建议时,不幸的是它似乎没有任何区别:

No route matches {:controller=>"devise/sites", :action=>"coupons"}
Extracted source (around line #9):

6: <div id="navcontainer">
7:   <ul id="navlist">
8:     <% nav.each do |anchor, action| %>
9:       <% active = current_page?(:controller => 'sites', :action => action) ? 'active' : '' %>
10:       <li class="<%= active %>"><%= link_to_unless_current(anchor, { :controller => 'sites', :action => action }) %></li>
11:     <% end -%>
12:   </ul>

Try doing 试着做

  <li class="<%= active %>"><%= link_to_unless_current(anchor, { :controller => 'sites', :action => action }) %></li>

The problem seems to be that, when you don't specify the controller in a link_to, it automatically uses the current page's controller. 问题似乎是,当你没有在link_to中指定controller时,它会自动使用当前页面的控制器。 In this case, it tried using devise/sessions controller, with coupons action. 在这种情况下,它尝试使用devise/sessions控制器,并使用coupons操作。

I got the same error when calling the helper from a rescue_from block inside application controller. 从应用程序控制器内的rescue_from块调用帮助程序时,我遇到了同样的错误。 What i did was prepend the helper with the fully qualified path like this 我所做的是使用像这样的完全限定路径前置帮助器

Rails.application.routes.url_helpers.new_user_session_path

Hope it helps future googlers. 希望它能帮助未来的googlers。

I'd look into namespacing like this: 我会调查这样的命名空间:

namespace :admin do root :to => "base#index" resources :users do resources :permissions end end namespace:admin do root:to =>“base #index”resources:用户做资源:权限结束

I would recommend using a routing helper for this instead of a hash. 我建议使用路由助手而不是散列。 Create routes for the site parts like this: 为站点部分创建路由,如下所示:

scope :controller => "sites" do
  get 'somewhere', :as => "somewhere"
  # etc...
end

Then reference them in your view as somewhere_url or somewhere_path . 然后在视图中将它们引用为somewhere_urlsomewhere_path

Check your controller and view routs 检查控制器并查看路径

Every one must come to user_sessions or user_session 每个人都必须来到user_sessionsuser_session

See this: 看到这个:

Form: 形成:

<%= form_for @user_sessions, :url => {:action => "create"} do |f| %>

Routes: 路线:

get "user_session/new"
    match 'login' => "user_sessions#new",      :as => :login 
    match 'logout' => "user_sessions#destroy", :as => :logout
resources :user_sessions

Controller also mention to user_sessions Controller还提到了user_sessions

Rails Devise routing error - “No route matches” (controller=>“devise/sessions”) Rails设计路由错误 - “无路由匹配”(controller =>“devise / sessions”)

this type of error will come 这种类型的错误会来临

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails设计帮助路由错误没有路由匹配“/ sessions / user” - Rails devise help routing error No route matches “/sessions/user” 没有路线符合“设计/会话” - No route matches “devise/sessions” rails3 devise - 没有路由匹配“/ sessions / user” - rails3 devise - no route matches “/sessions/user” 加载部分时出现奇怪的设计路由错误“没有路由匹配{:controller =&gt;“ devise / home”,:action =&gt;“ lng”,:locale =&gt;“ en”}“ - strange devise routing error on loading partial “ No route matches {:controller=>”devise/home“, :action=>”lng“, :locale=>”en“} ” 设计路由错误:没有路由匹配[PUT] - Devise routing error: No route matches [PUT] Rails没有路由匹配{:controller =&gt;“devise / products”} - Rails No route matches {:controller=>“devise/products”} Rails设计会话控制器 - Rails devise Sessions Controller 设计没有路线匹配会话/用户? - Devise no route matches sessions/users? 没有路线匹配{:controller =&gt;“ devise / dokumente”} - No route matches {:controller=>“devise/dokumente”} 设计命名空间 - ActionController :: RoutingError(无路由匹配{:action =>“new”,:controller =>“devise / sessions”}) - Devise in namespace - ActionController::RoutingError (No route matches {:action=>“new”, :controller=>“devise/sessions”})
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM