gpt4 book ai didi

ruby-on-rails - Rails 在设计中使用 link_to 的正确方法

转载 作者:行者123 更新时间:2023-12-02 01:16:40 25 4
gpt4 key购买 nike

我开始使用 rails 和 devise 进行身份验证,我想创建一个链接以在用户登录到管理页面时注销。

link_to code 的正确写法是什么?

这是我的 rake routes :

admin_index        /admin/index(.:format)         {:controller=>"admin/home", :action=>"index"}
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"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root / {:controller=>"home", :action=>"index"}

我试过了 <%= link_to "Sign Out", destroy_user_session_path %>但是当我点击链接时,它给了我错误:

No route matches [GET] "/users/sign_out"

最佳答案

从这里devise sample application , 推荐上Devise wiki :

<% if user_signed_in? %>
<li><%= link_to 'Edit account', edit_user_registration_path %></li>
<li><%= link_to 'Sign out', destroy_user_session_path, :method=>'delete' %></li>
<% end %>

关于ruby-on-rails - Rails 在设计中使用 link_to 的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10559841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com