当我尝试访问“登录”路线(GET / users / sign_in)时,我收到以下错误...
No route matches {:action=>"home", :controller=>"devise/pages"}
以下是服务器日志中的完整错误...
Started GET "/users/sign_in" for 127.0.0.1 at 2012-06-05 00:51:54 -0700
Processing by Devise::SessionsController#new as HTML
Rendered devise/shared/_links.erb (2.9ms)
Rendered devise/sessions/new.html.erb within layouts/application (33.5ms)
Rendered pages/_header.html.erb (75.9ms)
Completed 500 Internal Server Error in 349ms
ActionView::Template::Error (No route matches {:action=>"home", :controller=>"devise/pages"}):
这是我的应用程序/布局的主体......
<!-- BEGIN body -->
<body class="top">
<!-- BEGIN .container -->
<div class="container">
<%= render 'pages/header' %>
<%= render 'pages/menu' %>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
<!-- END .container -->
</div>
<%= render 'pages/footer' %>
</body>
我唯一拥有的控制器是“页面”控制器。另外,这是我的route.rb文件......
MyApp::Application.routes.draw do
devise_for :users
match '/contact', :to => 'pages#contact'
match '/news', :to => 'pages#news'
match '/home', :to => 'pages#home'
match '/features', :to => 'pages#features'
root :to => 'pages#home'
end
我不知道它是否与它有任何关系,但我也使用rails generate devise:views
命令生成了视图。
为什么在我执行GET / users / sign_in时尝试访问不存在的“设计/页面”控制器和“主页”操作?当我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 DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
root / {:controller=>"pages", :action=>"home"}
contact /contact(.:format) {:controller=>"pages", :action=>"contact"}
news /news(.:format) {:controller=>"pages", :action=>"news"}
home /home(.:format) {:controller=>"pages", :action=>"home"}
features /features(.:format) {:controller=>"pages", :action=>"features"}
非常感谢您的智慧!
编辑按要求添加“页面/菜单”...
<!-- BEGIN .menu-primary -->
<div class="menu-primary">
<table>
<tr>
<td class="menu">
<ul>
<li>
<a href="/news">News</a>
</li>
<li>
<a href="/features"><span>Shop Products</span></a>
<ul>
<li><a href="/features">Features</a></li>
</ul>
</li>
<li><a href="#"><span>Shop Parts</span></a><ul><li><a href="#">Controls (Coming Soon)</a></li><li><a href="#">Monitors (Coming Soon)</a></li><li><a href="#">Artwork (Coming Soon)</a></li><li><a href="#">Accessories (Coming Soon)</a></li></ul></li>
<li><a href="/contact">Contact Us</a></li>
</ul>
</td>
</tr>
</table>
<!-- END .menu-primary -->
</div>
UPDATE 在我的标题模板中,我有...
<%= link_to image_tag("mylogo.png", :alt=>"", :width=>"300", :height=>"100"), {:action => 'home', :controller => 'pages'} %>
并删除它可以让我的sign_in页面成功加载。为什么呢?!
答案 0 :(得分:4)
在构造{:action => 'home', :controller => 'pages'}
的URL时,Rails使用相对于控制器呈现当前视图的路径。
对于登录页面,这将是“设计/会话”,因此它在devise
命名空间中查找PagesController。
您可以通过添加反斜杠来修复它,以指定控制器位于根目录中,而不是在设计名称空间内。
替换:
{:action => 'home', :controller => 'pages'}
用这个:
{:action => 'home', :controller => '/pages'}
答案 1 :(得分:1)
“”,:width =&gt;“300”,:height =&gt;“100”),root_path%&gt;
我相信传递的link_to网址是设计范围的。您应该改为从rake路由生成的路径名。
答案 2 :(得分:0)
我在安装Devise时遇到同样的问题,之后无法运行任何东西。但在我的情况下,我试图使用Rails指向路线页面的路线来解决它:
<%= link_to 'Home', {:controller => 'frontpages', :action => 'services'}, class: 'footer-nav-link' %>
To:
<%= link_to 'Services', frontpages_services_path, class: 'footer-nav-link' %>
&#13;
一切都在追赶。
答案 3 :(得分:-1)
我找到了在相对文件中控制器启动时添加反斜杠'/'的地方,其中错误将显示在相关文件中(请参阅development.log中的错误) 就我而言:
= link_to "About", :controller => "/pages", :action => "about"
或
= link_to "Home", :controller => "/pages", :action => "home"