Hi, I have a controller which is looking for a set of Contacts from the Contacts table. Currently it looks like this:
@contacts = @campaign.contacts.find(:all, :order => "date_entered ASC")
The method in the contact.rb (Model) is this:
def status
return if statuses.empty?
a= statuses.find(:last).status << ' (' << statuses.find(:last).created_at.to_s(:long) << ')'
return a
end
For the most part, if there is a value in the "status", I no longer want to display it in the view.
Right now, status is polymorphic. That might've been a dumb idea, but I wanted the concept of status to apply across different models:
class Status < ActiveRecord::Base
attr_accessible :statusable_id, :statusable_type, :status
belongs_to :statusable, :polymorphic => true
end
# == Schema Information
#
# Table name: statuses
#
# id :integer not null, primary key
# statusable_id :integer
# statusable_type :string(255)
# status :string(255)
# created_at :datetime
# updated_at :datetime
#
I am assuming that if I can add that condition to the @contacts instance, that would take care of it. But I don't know how to write that condition in the controller on the .find method (if that is the right way to do it).
thanks.