开发者

How to hide a pages div if an attribute is blank on a page?

On my show page from a scaffold I have the following design:

<div id="show_location_main_area" class="grid_24">
    <p>
       <strong><%= @business_location.website %></strong>
    </p>
    <p>
      <strong><%=开发者_开发知识库 @business_location.address %></strong>
    </p>
</div>
<div class="grid_5">
     <%= gmaps(@json) %>
</div>

If @business_location.address is blank I don't want to show this part on the page:

<div class="grid_5">
    <%= gmaps(@json) %>
</div>

How is this done?

Thank you.


You can try following conditions -

unless @business_location.address.nil?
unless @business_location.address.empty?
if @business_location.address       

Example -

<% unless @business_location.address.nil? %>
    <div class="grid_5">
        <%= gmaps(@json) %>
    </div>
<% end %>


Just don't include it at all:

<% if @business_location.address.present? %>
    <div class="grid5">
        <%= gmaps(@json) %>
    </div>
<% end %>

Or, if you need the .grid5 <div> there for your HTML/CSS to work:

<div class="grid5">
    <% if @business_location.address.present? %>
        <%= gmaps(@json) %>
    <% end %>
</div>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜