Direct button depending on whether the user is logged in or not

Asked

Viewed 54 times

0

I have a button that leads to another screen, but if the user is not logged in to the system he should redirect to the login screen and not to the one that is already going. You can do this directly in link_to?

li= link_to 'Anuncie', new_subscription_path, class: "button"
  • Are you using what to authenticate your user? Devise?

  • Yes, I’m wearing the Devise

1 answer

0

I did it this way and it worked

li= link_to_if(@current_user.nil?, "Anuncie seu imóvel", new_user_session_path, class: "button") do
      = link_to  'Anuncie seu imóvel' ,new_subscription_path, class: "button"
      end

I wanted to know if a conditional would work using button_to instead of link_to

Browser other questions tagged

You are not signed in. Login or sign up in order to post.