If in my BusinessStore model/table I have the boolean:
create_table :business_stores do |t|
t.boolean :online_store
end
And in my view I wanted it to say "Online" instead of true or false as a string:
<% @business_stores.each do |business_store| %>
<%= business_store.online_store %>
<% end %>
How would it be done?
I go by the rule to keep the logic out of views, so I would create a method in the BusinessStore model:
def BusinessStore < ActiveRecord::Base
def status
if online_store
"Online"
else
"Some other type or blank"
end
end
end
Then in the view
<%= business_store.status %>
Maybe so:
<%= business_store.online_store ? "Online" : "Offline" %>
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With