I am trying to add the header to my rails application based on authenticating the user. 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
<% if user_signed_in? %>
Secondly add :
after method
, it's a key value pair
<%= 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 %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.