来自rake路线我在我的应用程序中得到了这个
new_admin_session GET /admins/sign_in(.:format) {:controller=>"devise/sessions", :action=>"new"}
admin_session POST /admins/sign_in(.:format) {:controller=>"devise/sessions", :action=>"create"}
destroy_admin_session GET /admins/sign_out(.:format) {:controller=>"devise/sessions", :action=>"destroy"}
admin_password POST /admins/password(.:format) {:controller=>"devise/passwords", :action=>"create"}
new_admin_password GET /admins/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"}
edit_admin_password GET /admins/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"}
admin_password PUT /admins/password(.:format) {:controller=>"devise/passwords", :action=>"update"}
admin_registration POST /admins(.:format) {:controller=>"devise/registrations", :action=>"create"}
new_admin_registration GET /admins/sign_up(.:format) {:controller=>"devise/registrations", :action=>"new"}
edit_admin_registration GET /admins/edit(.:format) {:controller=>"devise/registrations", :action=>"edit"}
admin_registration PUT /admins(.:format) {:controller=>"devise/registrations", :action=>"update"}
admin_registration DELETE /admins(.:format) {:controller=>"devise/registrations", :action=>"destroy"}
new_user_session GET /users/sign_in(.:format) {:controller=>"devise/sessions", :action=>"new"}
user_session POST /users/sign_in(.:format) {:controller=>"devise/sessions", :action=>"create"}
destroy_user_session GET /users/sign_out(.:format) {:controller=>"devise/sessions", :action=>"destroy"}
user_password POST /users/password(.:format) {:controller=>"devise/passwords", :action=>"create"}
new_user_password GET /users/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"}
edit_user_password GET /users/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"}
user_password PUT /users/password(.:format) {:controller=>"devise/passwords", :action=>"update"}
user_registration POST /users(.:format) {:controller=>"devise/registrations", :action=>"create"}
new_user_registration GET /users/sign_up(.:format) {:controller=>"devise/registrations", :action=>"new"}
edit_user_registration GET /users/edit(.:format) {:controller=>"devise/registrations", :action=>"edit"}
user_registration PUT /users(.:format) {:controller=>"devise/registrations", :action=>"update"}
user_registration DELETE /users(.:format) {:controller=>"devise/registrations", :action=>"destroy"}
root /(.:format) {:controller=>"devise/sessions", :action=>"new"}
change_authorization_rules GET /authorization_rules/change(.:format) {:controller=>"authorization_rules", :action=>"change"}
suggest_change_authorization_rules GET /authorization_rules/suggest_change(.:format) {:controller=>"authorization_rules", :action=>"suggest_change"}
graph_authorization_rules GET /authorization_rules/graph(.:format) {:controller=>"authorization_rules", :action=>"graph"}
authorization_rules GET /authorization_rules(.:format) {:controller=>"authorization_rules", :action=>"index"}
authorization_usages GET /authorization_usages(.:format) {:controller=>"authorization_usages", :action=>"index"}
在haml视图中我做
%html
%head
%title="Devise Demo"
= stylesheet_link_tag :all
= javascript_include_tag :defaults
= csrf_meta_tag
%body
%p.notice=notice
%p.alert=alert
- if current_user
= "Hello #{current_user.email} ("
= link_to 'Not you?', destroy_admin_session
= ")"
但我收到了错误
undefined local variable or method `destroy_admin_session' for #<#<Class:0x7f66ce2d3610>:0x7f66ce2cd1c0>
我显然错过了Rails 3中指定路线的明显缺失
布拉德
答案 0 :(得分:14)
关于rake routes
的诀窍是第一列中显示的路径不是助手的名称,而是前缀,因为有_url
和{ {1}}变体。
使用_path
。
答案 1 :(得分:0)
destroy_admin_session
应写为destroy_admin_session_path
答案 2 :(得分:0)
最后的用户_url