Reputation: 159
I would like to to do the following, any ideas
I have a Products model with two fields, both strings.
Name Position
I would like on the index pages for the products to display the Name in Red if the Positions field is blank in the database.
Thanks in advance
Upvotes: 0
Views: 179
Reputation: 30995
<span class="<%= product.position.nil? ? "red" : "blue" %>">
<%= product.name %>
</span>
Update:
Let's say you have code like you provided in comment, modify it to:
<td>
<%= link_to admin_printer_path(printer), :class => 'ico' do %>
<b<%= ' class="error"' unless printer.position? %>><%= printer.name %></b>
<% end %>
</td>
and in css file/section in header add (or modify according to your structure):
.error { color: red; }
Upvotes: 0
Reputation: 2575
Create helper
method to check if object is blank?
def set_css_class(object, css_class)
" #{css_class}" if object.blank?
end
Call it in your View
:
<div class="name <%= set_css_class(@poroduct.position, 'red') %>">
<%= @product.name %>
</div>
Upvotes: 1