How do I display a link to the开发者_如何学运维 article path if the article object is not null?
so something like:
<% if @article is not null %>
<a href="<%%= article_path @article >">link</a>
This reads nicer in my opinion:
<% if @article %>
<%= link_to 'link', @article %>
<% end %>
"If there is an article, link to it using the following display text and object."
A friend also points out that this could be shortened to this:
<%= link_to("link", @article) if @article %>
But personally, I prefer the first one.
<%= link_to 'link', @article unless @article.nil? %>
精彩评论