在视图中有一个字符串,它显示来自具有网站地址的数据库字符串。 如何使数据库中没有这个网站地址,字符串不会显示视图?
网站:
<%= link_to @ restaurant.site,url_with_protocol(@ restaurant.site)>
在缺席网站地址仍然是第一个字符串,我希望它只出现在地址
PS
可以这样做,就像编写这段代码一样:
<%if session [:user_id]%> <%end>
仅在用户注册时显示信息。
答案 0 :(得分:1)
就这样做。
<% if @restaurant.site %>
<%= link_to @restaurant.site, url_with_protocol(@restaurant.site) %>
<% end %>