Every repository with this icon (
Every repository with this icon (
Useful Code Snippets
Here are some helpful code snippets – how to check if a user is logged in, how to display conditional content based on the type of user or if they are logged in, etc.
If you have something you think would be useful to other people using these plugins, feel free to add to this list
Testing for a logged-in user in a view
Add comment
<% if logged_in? %> <% else %>You must be logged in to comment.
<% end %>Conditional partials
Testing for a logged-in user in a view (alternative)
I have had issues with using the ’@’ instance variable notation inside of views. So, for example, @current_user never seems to work for me. However, ‘self’ works instead. So, I use the following snippet inside views:
Welcome user
<% if logged_in? %>Welcome, <%= self.current_user.login %>
<% else %> <% end %>Alternate for current user
current_user(or whatever your accounted model is named) should work.
So, if your model is
Member
, there should be a
current_member






