Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would add an integer field to your Campaigncontacts resource called days_to_delay_communication_by, since this information relates to the association of a campaign and a contact rather than a contact itself.</p> <p>in your migration:</p> <pre><code>def self.up add_column(:campaigncontacts, :days_to_delay_communication_by, :integer) end def self.down remove_column(:campaigncontacts, :days_to_delay_communication_by) end </code></pre> <p>Now you can set that value by:</p> <pre><code>campaigncontact = Campaigncontacts.find(:first, :conditions =&gt; { :campaign_id =&gt; campaign_id, :contact_id =&gt; contact_id }) campaigncontact.days_to_delay_communication_by = 10 </code></pre> <p>Then in the admin side of your application you can have a controller and a view for campaign communications that lets you set the days_to_delay_communication_by field for campaigncontacts. I can expand on this further for you if you're interested, but I think you get the idea.</p> <p>Then you'll need to run a background process of some sort (probably a cron job, or use the <a href="http://github.com/tobi/delayed_job" rel="nofollow noreferrer">delayed_job plugin</a>), to find communications that haven't happened yet, and make them happen when the date has passed. You could do this in a rake task like so:</p> <pre><code>namespace :communications do namespace :monitor do desc 'Monitor and send communications for campaigns' task :erma =&gt; :environment do Rails.logger.info "-----BEGIN COMMUNICATION MONITORING-----" unsent_communications = Communication.all(:conditions =&gt; { :date_sent =&gt; nil}) unsent_communications.each do |communication| Rails.logger.info "**sending communication**" communication.send if communication.time_to_send &lt; Time.now Rails.logger.info "**communication sent**" end Rails.logger.info "-----END COMMUNICATION MONITORING-----" end #end erma task end #end sync namespace end #end db namespace </code></pre> <p>Then your cron job would do something like:</p> <pre><code>cd /path/to/application &amp;&amp; rake communications:monitor RAILS_ENV=production </code></pre> <p>Also, I'd consider changing the name of your join model to something more descriptive of it's purpose, for instance memberships, a campaign has many memberships and a contact has many memberships. Then a membership has a days_to_delay_communication field.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload