need an empty string, but getting an exception in ruby on rails

Posted by Jon on Stack Overflow See other posts from Stack Overflow or by Jon
Published on 2010-05-25T07:59:40Z Indexed on 2010/05/25 8:11 UTC
Read the original article Hit count: 280

controller

@articles = current_user.articles

view

<% @articles.each do |article| %>
  <%= link_to "#{article.title} , #{article.author.name}" articles_path%>
<% end %>

Sometimes the article has no author, so is null in the database, which results in the following error

You have a nil object when you didn't expect it! The error occurred while evaluating nil.name

I still want to output the article title in this scenario, whats the best way to do this please?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about exception