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 790761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:43:51+00:00 2026-05-14T21:43:51+00:00

I have a Campaign model which has_many Calls, Emails, and Letters. For now, these

  • 0

I have a Campaign model which has_many Calls, Emails, and Letters.

For now, these are each a separate Model with different controllers and actions (although I would like to start to think of ways to collapse them once the models and actions stabilize).

They do share two attributes at least: :days and :title

I would like a way to represent all the Calls, Emails, and Letters that belong_to a specific Campaign as a sortable collection (sortable by :days), in a way that outputs the model name and the path_to() for each.

For example (I know the below is not correct, but it represents the kind of output/format I’ve been trying to do:

@campaign_events.each do |campaign_event|
  <%= campaign_event.model_name %>
  <%= link_to campaign_event.title, #{model_name}_path(campaign_event) %>
end

Thanks so much. BTW, if this matters, I would then want to make the :days attribute editable_in_place.

Here is what I’ve got working, but want some additional insights

module CampaignsHelper
  def campaign_events
    return (@campaign.calls + @campaign.emails + @campaign.letters).sort{|a,b| a.days <=> b.days}
  end
end

In the VIEW:

<% @campaign_events = campaign_events %>
<% @campaign_events.each do |campaign_event| %>
    <% model_name = campaign_event.class.name.tableize.singularize %>
    <p>
        <%= link_to campaign_event.title,  send("#{model_name}_path", campaign_event) %> 
        <%= campaign_event.days %>
    </p>
<% end %>
  • 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-14T21:43:52+00:00Added an answer on May 14, 2026 at 9:43 pm

    Like this?

    # controller
    @campaign = Campaign.find(params[:id])
    @campaign_events = (@campaign.calls + @campaign.emails + @campaign.letters).sort{|a,b| a.days <=> b.days}
    
    # view
    @campaign_events.each do |campaign_event|
      <%= campaign_event.model_name %>
      <%= link_to campaign_event.title, #{model_name}_path(campaign_event) %>
    end
    

    In controller you find all campaign events and sort it by days field

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

Sidebar

Related Questions

I have a model like: CAMPAIGN_TYPES = ( ('email','Email'), ('display','Display'), ('search','Search'), ) class Campaign(models.Model):
I have two models: class Contact(models.Model): name = models.CharField(max_length=255) class Campaign(models.Model): contact = models.ForeignKey(Contact,
I have xpath page.search(//table[@class='campaign']//table) which returns two tables. I need to choose only first
I need help refactoring this multi-loop thing. Here is what I have: Campaign has_many
I have a model Campaign and the campaign/show goes through a loop of the
I have several models: Email Letter Call All three belong to a model Campaign.
I have a model Campain which has many Media . I do this: Campain.all.medias
In my app model, I have a BooleanField : campaign = models.BooleanField(default=False, db_index=True, verbose_name=_('processed'),
I have a model Goal that has four types of children (which all have
I have the following on my edit screen: <label for=campaign.CandidateID>Candidate:</label> <%= Html.DropDownList(Campaign.CandidateID, Model.Candidates, Choose...)%>

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.