How to hide an entire DIV in a rails project if no data is being passed to it from the CMS?

StackOverflow https://stackoverflow.com/questions/19733393

سؤال

Using Refinery CMS to create product pages in our prototype. An admin can add a link to the main product page, and it will display similar to

Product Links
www.example.com/product/1
www.example.com/product/2

here is a screenshot of how it currently is being displayed

when product link is added

However, there will not always be a case when the ink is added. And this looks weird to have that field but no links in there because every element has margin-bottom:30px;

When no link is added

So my question is how do I make the element not show up at all if nothing is passed to it. Here is the code for the element:

HTML

<div class="contentPageElement">
  <h3>Product Links</h3>
  <%= link_to @discussion.link.to_s, @discussion.link %>
</div>
هل كانت مفيدة؟

المحلول

you can either put it in helper,or do something like this.

<% unless @discussion.link.empty? %>
<div class="contentPageElement">
  <h3>Product Links</h3>
  <%= link_to @discussion.link.to_s, @discussion.link %>
</div>
<% end %>

نصائح أخرى

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top