Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 自定义布尔文本?_Ruby On Rails_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 自定义布尔文本?

Ruby on rails 自定义布尔文本?,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,如果在我的BusinessStore模型/表中有布尔值: create_table :business_stores do |t| t.boolean :online_store end 在我看来,我希望它说“在线”,而不是像字符串一样的真或假: <% @business_stores.each do |business_store| %> <%= business_store.online_store %> <% end %> 怎么做

如果在我的BusinessStore模型/表中有布尔值:

create_table :business_stores do |t|
    t.boolean :online_store
end
在我看来,我希望它说“在线”,而不是像字符串一样的真或假:

<% @business_stores.each do |business_store| %>
    <%= business_store.online_store %>
<% end %>

怎么做呢?

也许是这样:

<%= business_store.online_store ? "Online" : "Offline" %>


我按照规则将逻辑排除在视图之外,因此我将在BusinessStore模型中创建一个方法:

def BusinessStore < ActiveRecord::Base
    def status
       if online_store
         "Online"
       else
         "Some other type or blank"
       end
    end
end
def BusinessStore
然后在视图中

<%= business_store.status %>

<%= business_store.status %>