2011-11-23 88 views
3

如果我BusinessStore模型/表我有布爾:自定義布爾文本?

create_table :business_stores do |t| 
    t.boolean :online_store 
end 

在我看來,我想它說:「在線」,而不是真或假的字符串:

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

如何它會完成嗎?

回答

3
<% @business_stores.each do |business_store| %> 
    <%= "Online" if business_store.online_store %> 
<% end %> 
4

也許是這樣的:

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

5

我去的規則,以保持邏輯出來的意見,所以我將創建一個BusinessStore模型的方法:在視圖

def BusinessStore < ActiveRecord::Base 
    def status 
     if online_store 
     "Online" 
     else 
     "Some other type or blank" 
     end 
    end 
end 

然後

<%= business_store.status %>