Html 如何显示对象';属性作为不同的字符串?

Html 如何显示对象';属性作为不同的字符串?,html,ruby-on-rails,ruby,ruby-on-rails-3,Html,Ruby On Rails,Ruby,Ruby On Rails 3,RubyonRails3:我有一个表,其中一列根据objects布尔属性显示true或false。我想让它显示是或否 这是我的桌子: <table id="resellers" class="table table-striped table-hover table-bordered" style="background-color: white"> <thead> <button type="button" class="reset">Reset S

RubyonRails3:我有一个表,其中一列根据objects布尔属性显示true或false。我想让它显示是或否

这是我的桌子:

<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\u 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 %>


哇,太棒了!:)谢谢你知道我在哪里能读到这项技术吗?它叫做三元运算符。几乎所有的语言都有一种。这是一个包含一些Ruby示例和解释的页面:您的HTML无效,a.对于HTML无效,请阅读我链接到的规范。如果浏览器以各种方式重写您的不完全HTML,请不要感到惊讶。