我有这条路线
profile GET /contacts/:id(.:format) {:controller=>"my_devise/contacts", :action=>"profile"}
这是我的控制器/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) %>
如果我在 url 上的view/layouts/application.html.erb 文件中有此链接,我http://localhost:3000/contacts/1
没有错误,但如果我尝试点击 url http://localhost:3000/contacts
,我会收到以下错误
Routing Error
No route matches {:controller=>"my_devise/contacts", :action=>"profile"}
如果我删除 application.html.erb 文件中的链接并点击http://localhost:3000/contacts
,错误就会消失。
为什么该链接会导致此错误?
编辑
完整的路线文件
$ rake routes
users_sign_out GET /users/sign_out(.:format) {:controller=>"devise/sessions", :action=>"destroy"}
users_sign_in GET /users/sign_in(.:format) {:controller=>"my_devise/sessions", :action=>"new"}
home GET /home(.:format) {:action=>"index", :controller=>"my_devise/sessions"}
contacts GET /contacts(.:format) {:action=>"list", :controller=>"my_devise/contacts"}
profile GET /contacts/:id(.:format) {:controller=>"my_devise/contacts", :action=>"profile"}
edit_profile GET /contacts/:id/edit(.:format) {:controller=>"my_devise/contacts", :action=>"edit"}
POST /contacts/:id/edit(.:format) {:controller=>"my_devise/contacts", :action=>"update_user"}
more GET /more/:id(.:format) {:controller=>"my_devise/contacts", :action=>"more"}
POST /home(.:format) {:action=>"create_new_user", :controller=>"my_devise/sessions"}
users_sign_up GET /users/sign_up(.:format) {:controller=>"my_devise/registrations", :action=>"new"}
POST /users/sign_up(.:format) {:controller=>"my_devise/registrations", :action=>"new"}
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"}
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"my_devise/sessions"}
POST /users/sign_in(.:format) {:action=>"create", :controller=>"my_devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"my_devise/sessions"}
POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
GET /users/cancel(.:format) {:action=>"cancel", :controller=>"my_devise/registrations"}
POST /users(.:format) {:action=>"create", :controller=>"my_devise/registrations"}
GET /users/sign_up(.:format) {:action=>"new", :controller=>"my_devise/registrations"}
GET /users/edit(.:format) {:action=>"edit", :controller=>"my_devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"my_devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"my_devise/registrations"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root / {:controller=>"home", :action=>"index"}
root / {:controller=>"home", :action=>"index"}