Ruby on Rails 3: У меня есть таблица с одним столбцом, отображающая true или false на основе атрибута boolean. Я хочу, чтобы он показывал "да" или "нет".
Вот мой стол:
<table id="resellers" class="table table-striped table-hover table-bordered" style="background-color: white">
<thead>
<button type="button" class="reset">Reset Search</button>
<th width="12%" onMouseOver="this.style.color='#00F'" onMouseOut="this.style.color='black'">Contact Name</th>
<th width="12%" onMouseOver="this.style.color='#00F'" onMouseOut="this.style.color='black'">Reseller</th>
<th width="11%" onMouseOver="this.style.color='#00F'" onMouseOut="this.style.color='black'">Region</th>
<th width="10%" onMouseOver="this.style.color='#00F'" onMouseOut="this.style.color='black'">Country</th>
<th width="18%" onMouseOver="this.style.color='#00F'" onMouseOut="this.style.color='black'">Email</th>
<th width="11%" onMouseOver="this.style.color='#00F'" onMouseOut="this.style.color='black'">Distributor</th>
<th width="11%" onMouseOver="this.style.color='#00F'" onMouseOut="this.style.color='black'">Registered</th>
<th width="10%" onMouseOver="this.style.color='#00F'" onMouseOut="this.style.color='black'">Approved</th>
<th width="5%" class="filter-false"></th>
</thead>
<tbody>
<% #current_grandstreamer.resellers.each do |reseller| %>
<% @resellers.each do |reseller| %>
<tr>
<td><%= reseller.contact_name %></td>
<td><%= link_to reseller.company_name, grandstreamers_reseller_path(reseller) %></td>
<td><%= reseller.company_region %></td>
<td><%= reseller.company_country %></td>
<td><%= reseller.contact_email %></td>
<td><%= reseller.distributor %></td>
<td><%= reseller.created_at.to_date.to_s %></td>
<td><%= reseller.approved %></td>
<td><%= link_to "Edit", edit_grandstreamers_reseller_path(reseller) %>
</tr>
<% end %>
</tbody>
Есть ли способ сделать оператор if или сделать переменную в контроллере для отображения? благодаря
Что-то вроде этого будет работать:
<%= reseller.approved ? "Yes" : "No" %>
То, что мне нравится делать, - это расширение булевых классов с помощью помощника to_yesno.
config/initializers/ruby_extensions.rb:
class TrueClass
def to_yesno
'yes'
end
end
class FalseClass
def to_yesno
'no'
end
end
Затем в моих представлениях для любого логического значения, которое я могу просто сделать:
<%= reseller.approved.to_yesno %>
<thead>
могут быть только<tr>
дети .