"devise/sessions")-6ren"> "devise/sessions")-编辑 2:看起来对我来说一个快速的临时修复是在我的 link_to_unless_current 和 current_page 方法中的 Controller 名称前面添加一个正斜杠“/”。例如 '-6ren">
gpt4 book ai didi

ruby-on-rails - Rails Devise 路由错误 - "No route matches"( Controller = >"devise/sessions")

转载 作者:数据小太阳 更新时间:2023-10-29 07:18:51 32 4
gpt4 key购买 nike

编辑 2:看起来对我来说一个快速的临时修复是在我的 link_to_unless_current 和 current_page 方法中的 Controller 名称前面添加一个正斜杠“/”。例如

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

这里是关于我遇到的问题的更多信息,以防其他人遇到同样的事情。 https://github.com/plataformatec/devise/issues/471

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

当我使导航 (_header.html.erb) 动态时,我的设计路径中断了。我希望这是一个简单的修复,但真的丢失了 atm。我网站上的每个页面都可以正常工作,除非我转到/admin 然后出现以下路由错误:

这是我收到的确切错误:

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'

这是 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'

这是 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 -%>

这是 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"}

感谢您的关注!

编辑 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>

最佳答案

尝试做

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

问题似乎是,当您没有在 link_to 中指定 controller 时,它会自动使用当前页面的 Controller 。在这种情况下,它尝试使用 devise/sessions Controller 和 coupons 操作。

关于ruby-on-rails - Rails Devise 路由错误 - "No route matches"( Controller = >"devise/sessions"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5292775/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com