当前位置:  开发笔记 > 编程语言 > 正文

在Rails 3 haml视图中使用devise命名的路由

如何解决《在Rails3haml视图中使用devise命名的路由》经验,为你挑选了1个好方法。

从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 #<#:0x7f66ce2cd1c0>

我显然错过了Rails 3中命名路由的明显缺失

布拉德



1> Robert Speic..:

诀窍rake routes是第一列中显示的路径不是助手的名称,它是前缀,因为有_url_path变体.

使用destroy_admin_session_path.

推荐阅读
U友50081205_653
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有