title: Using if statement in rails to show a link_to tag based on who is signed in?
body: <p>beginner in Rails and I am making a rails news page with devise authentication and when someone visits localhost:3000/news, it shows a list of news. I am trying to show "edit" link only if it was posted by current user or if the current user's username is "admin". Here is my code for it  </p>
  
  <pre><code>    &lt;% @news.each do |element| %&gt;
        &lt;p&gt;Title: &lt;%= element.title%&gt;&lt;/p&gt;
        &lt;p&gt;&lt;%= element.body%&gt;&lt;/p&gt;
        &lt;li&gt;Posted by: &lt;%= element.user.username %&gt;&lt;/li&gt;
        &lt;li&gt;&lt;%= link_to "Comments", newsone_path(element) %&gt;&lt;/li&gt;
        &lt;% if current_user.username == "admin" || current_user == element.user %&gt;
           &lt;li&gt;&lt;%= link_to "Edit this drink", edit_news_path(element) %&gt;&lt;/li&gt;
        &lt;% end %&gt;
      &lt;% end %&gt;
  </code></pre>
  
  <p>It works and it shows the edit link only if username "admin" is signed in or if the user who posted it is signed in. But if I try to go to <code>localhost:3000/news</code> without signing in, it shows an error </p>
  
  <blockquote>
    <p>"undefined method `username' for nil:NilClass" on line "&lt;% if
    current_user.username == "admin" || current_user == element.user %>"</p>
  </blockquote>
  
  <p><br>
  I think this maybe because when I am signed out, there is no username maybe? How do I get around this please help?</p>