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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:15:52+00:00 2026-06-06T22:15:52+00:00

new on ruby and using windows xp and rails 3, i want to send

  • 0

new on ruby and using windows xp and rails 3, i want to send emails to the users every 7 days for 34 weeks, i have usermailer that send emails every 7 days i want also for 34 weeks??

i have user mailer send emails to user, and i have defined a method to send emails every 7 days
and call it from a batch file using also a windows task scheduler
also i want to know which week is the user now in??

e.g user gets pregnant on April and singed up in June, then there will be a welcome message,then the first 8 weeks of her pregnancy wasn`t in our records that means the emails will start from week number 9 because 34 – 8 = 26 weeks so the user will receive 26 emails (1 email every 1 week).

my model:

class Dop < ActiveRecord::Base
  attr_accessible :date, :mail, :name
  validates_presence_of :name
  validates_presence_of :mail
  validates_uniqueness_of :mail
  validates_format_of :mail, :with =>
  %r{^(?:[_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-zA-Z0-9\-\.] 
  +)*(\.[a-z]{2,4})$}i

  def self.send_mail
    Dop.all.each do |dop|
      UserMailer.welcome_email(dop).deliver if dop.date.to_time <= Time.now - 7.day
    end
  end
end

my batch file :

 echo rails run
 cd c:\dop
 rails r "Dop.send_mail"

 echo done
 pause

Dop is refer to date of pregnancy.

  • 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-06-06T22:15:53+00:00Added an answer on June 6, 2026 at 10:15 pm

    Based on your environment, a pure ruby solution would look like this:

    class Dop < ActiveRecord::Base
      def self.send_mail
        Dop.all.each do |dop|
          UserMailer.welcome_email(dop).deliver if within_thirty_four_weeks?(date) && seventh_day(dop.date) 
        end
      end
    
      def self.seventh_day?(date)
        days_diff % 7 == 0
      end
    
      def self.within_thirty_four_weeks?(date)
        days_diff(date) <= 34.weeks
      end
    
      def self.days_diff(date)
        (Time.zone.now - date).to_i / 1.day
      end
    end
    

    However, I prefer a more database solution. Wherein this gets more complicated, sqlite does not have the same date functions as MySql or Postgres. (Sqlite can be patched to keep your test/development environment like production, but I’m saving that for another question.)

    class Dop < ActiveRecord::Base
      def self.send_mail
        Dop.where("(julianday('now') - julianday(date(date))) % 7 = 0").
            where("date('now', '-238 days') < date").
            each do |dop|
              UserMailer.welcome_email(dop).deliver
        end
      end
    end
    

    Personally, the database solution (option 2), is the most elegant solution. Though it is more fragile, because it is specific to sqlite’s date functions.

    Schedule this to run nightly and it will email every 7 days for 34 weeks.

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

Sidebar

Related Questions

I have built a very simple blog application using Ruby on Rails. New to
I'm new to Ruby and Rails, but my team is interested in using Redmine
I have the Ruby code below, I am using windows API calls and I
I am using jQuery and Ruby On Rails. I have an ajax call $.get()
I have been attempting to create a Windows Application using Iron Ruby Version 1.1
In my project, I want to re-open a new tab using ruby code .
I am new to Ruby on Rails. I have read many article regarding easy
I just installed ruby on rails on my new computer ( I was using
I have a Rails 3.2.3 app (ruby 1.9.3p125) deployed on a Windows 2003 R2
Helo, I am pretty new to Ruby (using 1.8.6) and need to know whether

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.