GVS
GVS

Reputation: 229

Adding a class to link_to

I have been trying to add a class to my link_to for over an hour now. No matter what I try, I get an error.

<% if user_signed_in? %>
  <li>
  <%= link_to('Sign out', destroy_user_session_path, :method => :delete) %>
  </li>
<% else %>
  <li>
  <%= link_to('Sign in', new_user_session_path) %>
  </li>
<% end %>

I am trying to add :class => "page-scroll btn-signin" to both of my link_to lines.

Upvotes: 3

Views: 3203

Answers (2)

GVS
GVS

Reputation: 229

I solved the problem

<%= link_to 'Sign out', destroy_user_session_path, :method => :delete, :class => "page-scroll btn-signin" %>

This code works correctly.

Upvotes: 2

Emu
Emu

Reputation: 5905

<%= link_to 'Sign in', new_user_session_path, :class => "page-scroll btn-signin" %>

and

<%= link_to 'Sign out', destroy_user_session_path, :method => :delete, :class => "page-scroll btn-signin" %>

More info

EDIT

Destructive actions should be performed as a form submission - link

use button_to on Sign Out.

<%= button_to "Sign out", destroy_user_session_path, :method=>:delete, :class => "page-scroll btn-signin" %>

Upvotes: 0

Related Questions