开发者

Display post link if article object is not null?

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? %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜