Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 758971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:32:32+00:00 2026-05-14T15:32:32+00:00

I am probably going to need to refactor in two steps since I’m still

  • 0

I am probably going to need to refactor in two steps since I’m still developing the project and learning the use-cases as I go along since it is to scratch my own itch. I have three models: Letters, Calls, Emails. They have some similarilty, but I anticipate they also will have some different attributes as you can tell from their description.

Ideally I could refactor them as Events, with a type as Letters, Calls, Emails, but didn’t know how to extend subclasses.

My immediate need is this: I have a helper which checks on the status of whether an email (for example) was sent to a specific contact:

def show_email_status(contact, email)

  @contact_email = ContactEmail.find(:first,
     :conditions => {:contact_id => contact.id, :email_id => email.id })
  if ! @contact_email.nil?
    return @contact_email.status
  end
end

I realized that I, of course, want to know the status for whether a call was made to a contact as well, so I wrote:

def show_call_status(contact, call)

  @contact_call = ContactCall.find(:first, 
     :conditions => {:contact_id => contact.id, :call_id => call.id })
  if ! @contact_call.nil?
    return @contact_call.status
  end
end

I would love to be able to just have a single helper show_status where I can say show_status(contact,call) or show_status(contact,email) and it would know whether to look for the object @contact_call or @contact_email.

Yes, it would be easier if it were just @contact_event, but I want to do a small refactoring while I get the program up and running, and this would make the ability to do a history for a given contact much easier.

Thanks!

NOTE: Currently I have status as an attribute of contact_email, contact_call, etc. Contact_email only gets created when the email is sent, so there is not contact_email if an email hasn’t been sent, and I need to know that the status is “unsent”…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:32:32+00:00Added an answer on May 14, 2026 at 3:32 pm

    You can move the helper to the Contact model.

    class Contact < ActiveRecord::Base
    
      has_many :contact_emails
      has_many :contact_calls
      has_many :contact_letters
    
      def event_status event
        assoc_name = "Contact#{event.class.name}".pluralize.underscore
        foreign_key = "%s_id" % event.class.name.underscore
        ce = send(assoc_name).first(:conditions => {foreign_key => event.id})
        ce ? ce.status : nil
      end
    
    end
    

    Now you can get the status as follows:

    contact.event_status(email1)
    contact.event_status(letter2)
    contact.event_status(call12)
    

    This alleviates the need for different helpers. One method to address different events.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably going to sound backwards. I need for a form to submit
I'm going to need to push and pull files from a SharePoint site that
I want to implement an override of equals that compares two Java Queue objects
Ok here's my scenario (be kind, only been using Python for a short while):
Ok, I have a database with with a table for storing classified posts, each
I have a Chrome extension that relies heavily on a server back end to
I am toying around with building a rails app in the near future and
This is a rather random problem. I'm using CSS3Pie to handle CSS3 compatibility in
I've done a lot of projects and a lot of different build systems and
My team is tasked with quickly evaluating SproutCore and a couple of other alternatives.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.