简体   繁体   English

如何检查用户是否使用 rails devise 登录?

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

I am trying to add the header to my rails application based on authenticating the user.我正在尝试根据对用户的身份验证将标头添加到我的 rails 应用程序中。 So here I am checking that if the user has logged in or signed in and then adding login/logout link based on that.所以在这里我检查用户是否已登录或登录,然后基于此添加登录/注销链接。

But I am getting the following error:但我收到以下错误:

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

Here's what I have tried:这是我尝试过的:

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

How can I resolve this?我该如何解决这个问题?

First of all remove do from this line, you don't need that首先从这一行中删除do ,你不需要那个

<% if user_signed_in? %>

Secondly add : after method , it's a key value pair其次添加: method之后,它是一个键值对

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

Hope that helps!希望有帮助!

You are making a syntax error in method delete.您在方法删除中犯了语法错误。 Copy the below code复制下面的代码

<% 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