簡體   English   中英

如何檢查用戶是否使用 rails devise 登錄?

[英]How can I check if user is signed in with rails devise?

我正在嘗試根據對用戶的身份驗證將標頭添加到我的 rails 應用程序中。 所以在這里我檢查用戶是否已登錄或登錄,然后基於此添加登錄/注銷鏈接。

但我收到以下錯誤:

application.html.erb:16: syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '(' ...roy_user_session_path, method :delete );@output_buffer.safe_

這是我嘗試過的:

<% if user_signed_in? do %> 
    <%= link_to "Log out", destroy_user_session_path, method :delete %>
<% else %>
    <%= link_to "login", new_user_session_path %>
<% end %>

我該如何解決這個問題?

首先從這一行中刪除do ,你不需要那個

<% if user_signed_in? %>

其次添加: method之后,它是一個鍵值對

<%= link_to "Log out", destroy_user_session_path, method: :delete %>

希望有幫助!

您在方法刪除中犯了語法錯誤。 復制下面的代碼

<% if user_signed_in? %>
    <%= link_to "Log out", destroy_user_session_path, :method=>'delete'%>
<% else %>
    <%= link_to "login", new_user_session_path %>
<% end %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM