rails插件devise错误查找与解决

来源:互联网 发布:ansible支持windows吗 编辑:程序博客网 时间:2024/06/03 16:08

感谢 这篇文章 ,要不然我还在挠头呢。

事情是这样开始的,我安装了devise,访问 /sign_in 时报了错:

No route matches {:controller=>"devise/today"}
而且只要是devise的routes都无法访问,都是这个错。google了一下,发现这个问题是个老生常谈的问题,很多人都问了这个问题,但都不是我要的答案,因为不知道错在哪里了。

下面是解决方案(又长知识了。。。贫乏啊。。。):

打开development.rb,添加代码:

config.log_level = :debug

我用的是开发环境,是什么环境就在对应的文件中添加这行日志代码。

重启服务器,再次运行这个错误页面,查看development.log:


Started GET "/users/sign_up" for 127.0.0.1 at 2012-10-17 11:44:16 +0800Processing by Devise::RegistrationsController#new as HTML  Rendered devise/registrations/new.html.erb within layouts/application (4.6ms)Completed 500 Internal Server Error in 25msActionController::RoutingError (No route matches {:controller=>"devise/today"}):  app/views/layouts/application.html.erb:20:in `_app_views_layouts_application_html_erb___15093691_77891530'  Rendered /home/duan/.rvm/gems/ruby-1.9.3-p194@rails3/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.1ms)

第三行,已经开始render new.html.erb文件了,这个是devise生成文件,能走进去应该说没有错的了,下面可以看出,错误出在application.html.erb的第20行,赶紧去看了看,还真是!

我写了这样一行代码:

<%= link_to "today", :controller => 'today', :action => 'index' %>

找到位置就好办!只要改写成:

<%= link_to "today", :controller => '/today', :action => 'index' %>
就万事ok,原因嘛。。。。。devise在render一个view时,会把today当成devise的一个控制器处理,这是路由命名空间的问题。

原创粉丝点击