从某些页面获取路由错误

时间:2012-11-09 05:41:12

标签: ruby-on-rails ruby ruby-on-rails-3 devise

我有这条路线

profile GET /contacts/:id(.:format) {:controller=>"my_devise/contacts", :action=>"profile"}

这是我的controllers / application_controller.rb

class ApplicationController < ActionController::Base
  protect_from_forgery

  before_filter :get_current_user

    def get_current_user
        @current_user = current_user
    end

end

如果我在网址<%= link_to "Profile", profile_path(@current_user) %>的视图/ layouts / application.html.erb文件http://localhost:3000/contacts/1中有此链接,我没有错误,但如果我尝试点击网址{{1我收到以下错误

http://localhost:3000/contacts

如果我删除了我的application.html.erb文件中的链接并点击Routing Error No route matches {:controller=>"my_devise/contacts", :action=>"profile"} ,则错误就会消失。

为什么该链接会导致此错误?

修改

完整路线档案

http://localhost:3000/contacts

2 个答案:

答案 0 :(得分:1)

要回答你的实际问题,那是因为你没有路线(/contacts - 注意没有身份证明)。您的路线是/contacts/:id(.:format) - 格式是可选的,但ID不是。您还需要使id可选,或者创建另一条路径。

答案 1 :(得分:0)

路线就像这样

联系人GET /contacts(.:format){:action =&gt;&#34; list&#34;,:controller =&gt;&#34; my_devise / contacts&#34;}

这里我们还要提供格式。如果我们提供联系人,它将抛出路由错误。所以请输入格式。

相关问题