I have the following in the view:
<% unless contact_email.statuses.empty?%>
(<%= contact_email.statuses.find(:last).status%>)
<% end %>
contact_email is an instance of a specific model.
Could I do something like this?
class ContactEmail < ActiveRecord::Base
attr_accessible :contact_id, :email_id, :status, :subject, :body, :date_created, :date_sent
def status
unless contact_email.statuses.empty?
contact_email.statuses.find(:last).status
end
end
end
is there a better way to do this? is there a way to use the || operator for a default if empty?
Basically, I would like to be able to do the following in the View:
<%= contact_email.status =>
IF there is a value, then display it, if not, show nothing.