开发者

named routes with devise in Rails 3 haml view

from rake routes I get this in my application

                 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"}
  开发者_StackOverflow                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"}

In a haml view I do

%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
    = ")"

but I get the error

undefined local variable or method `destroy_admin_session' for #<#<Class:0x7f66ce2d3610>:0x7f66ce2cd1c0>

I'm obviously missing the abvious about named routes in Rails 3

Brad


The trick about rake routes is that the path shown in the first column isn't the name of the helper, it's the prefix, because there are _url and _path variants.

Use destroy_admin_session_path.


user _url at the end


destroy_admin_session should be written as destroy_admin_session_path

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜