0

I have this idea that I want "Logged in" to be show in the upper corner of my webpage when user_signed_in? is true, but when user_signed_in? is false then I want it to only simply put "Login".

user_signed_in? is the helper method for Devise. I think.

How do I actually make this work. I tried this:

<%= if user_signed_in? => true puts "Logged In" else puts "Login" %>
<% end %>
<% end %>

This doesn't work though. Any ideas ?

1
  • Welcome to StackOverflow! I hope my answer helped you. If it did, please accept it (by clicking the check mark)! If not, let me know what you're still confused about by editing the question and I'll be happy to help.
    – Eric
    Jan 15, 2013 at 10:10

1 Answer 1

5

you should look into Ruby syntax a little more (here, for example). Try this:

<% if user_signed_in? %>
  Logged In
<% else %>
  <%= link_to 'Login', ... %> # substitute the ... for whatever path goes to login
<% end %>

Note that the <%= part is only used when the embedded ruby will actually be returning content that will be rendered by the browser (aka converted to html). Since all your embedded ruby in your example is only control flow, don't use the =, since the browser won't actually see any of it. However, the link_to method returns a link, which is actual rendered content, so we need the =.

Also note that since this is a view file--and thus is basically an enhanced html file--you don't need the "puts" for raw content like "Logged in". In fact, puts wouldn't bring the content to the browser, but instead to wherever STDOUT leads in Rails apps (the logger? not sure)

4
  • I'll try this out, Thanks ;) I'll take a look athe control flow example zetcode thingy. I'll get back and tell you if it worked Jan 15, 2013 at 10:10
  • Good luck! Rails syntax can get complicated since you're writing Ruby, Rails-enhanced Ruby, and html/embedded Ruby, so it can get overwhelming as a beginner. Stick with it and check out the multitude of great tutorials available online (and StackOverflow) and you'll get the hang of it.
    – Eric
    Jan 15, 2013 at 10:14
  • @MarcusTheBuilder: You can find more helpers related to devise at github.com/plataformatec/devise#controller-filters-and-helpers Jan 15, 2013 at 10:21
  • It worked terrifically. Thank you A LOT! :D Check-mark coming about wondering! Jan 15, 2013 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.