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

  • SEARCH
  • Home
  • 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 7895415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:38:17+00:00 2026-06-03T07:38:17+00:00

I have a rails application what I want to send my users notifications when

  • 0

I have a rails application what I want to send my users notifications when certain criteria are met. I can do this through a rake task. Currently I’m able to select the records that meet the criteria and email them to a specific address. The issue is that it sends ALL the records for all the accounts. Here’s what I have in the rake task:

task :send_reminds => :environment do
    equipment = Equipment.where("calibration_date <= ?", Date.today)
    EquipmentMailer.out_of_calibration(equipment).deliver
end

Here is the code for my EquipmentMailer:

class EquipmentMailer < ActionMailer::Base
  default :from => "mark.odonnell@azzurgroup.com"

  def out_of_calibration(equipment)
    @equipment = Equipment.where("calibration_date <= ?", Date.today)
    mail(:to => "markaodonnell@gmail.com", :subject => "Equipment is out of calibration")
  end
end

Here is the code for my HTML email (which works as expected):

The following Equipment is Due:
<br></br>
<table>
  <tr>
    <th>Equipment Name</th>
    <th>   </th>
    <th>Calibration Due Date</th>
  </tr>
  <% @equipment.each do |equipment| %>
  <tr>
    <td><%= equipment.equipment_id %></td>
    <td>  </td>
    <td><%= equipment.calibration_date %></td>
  </tr>
<% end %>
</table>

As you can see I’m sending the email directly to myself and receive the equipment list that meets the criteria. But that is unacceptable of course. I want the email to go to all the users within an account that has equipment that is out of calibration. Here are my models:

Equipment.rb

class Equipment < ActiveRecord::Base
  acts_as_tenant(:account)

  validates :equipment_id, presence: true
  validates :location, presence: true

  validates_uniqueness_to_tenant :serial_number

  has_many :assets, :dependent => :destroy
  accepts_nested_attributes_for :assets, :allow_destroy => true

  has_paper_trail


def self.text_search(query)
    if query.present?
  search(query)
    else
        scoped
    end
end

User.rb

    class User < ActiveRecord::Base
  acts_as_tenant(:account)
  validates_uniqueness_to_tenant :email

   attr_accessible :name, :email, :password, :password_confirmation, :title, :company,
                                    :phone, :mobile,     :admin
  has_secure_password
  before_save :create_remember_token

  belongs_to :account

  validates :name, presence: true, length: { maximum: 50 }
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence:   true,
                format:     { with: VALID_EMAIL_REGEX }
  validates :password, length: { minimum: 6 }
  validates :password_confirmation, presence: true

#  has_paper_trail

  private

    def create_remember_token
      self.remember_token = SecureRandom.urlsafe_base64
    end
end

Account.rb

    class Account < ActiveRecord::Base
  attr_accessible :subdomain, :email
  VALID_SUBDOMAIN_REGEX = /\A[\w+\-.]+(-[a-z\d])+(-[a-z\d])/i
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :subdomain, :presence => true, 
            :uniqueness => true
  validates :email, :presence => true,
            format: { with: VALID_EMAIL_REGEX }

  validates_presence_of :plan_id  

  belongs_to :plan

  has_many  :users
  has_many  :equipment, :through => :users

  before_save { |account| account.subdomain = account.subdomain.downcase }
end

I have tried something like this for the mail(:to => user.email) instead of a direct address while limiting the equipment list to be specific to an account and it’s users.

@equipment = Equipment.where("calibration_date <= ?", Date.today)  
  @equipment.each do |equipment|
    equipment.accounts.each do |account|
      accounts.users.each do |user|
        user.email.each do |email|
          mail(:to => email, :subject => "Equipment is out of calibration"
        end
      end
    end
  end

The rake task will run without errors but I get no emails. Thoughts? BTW, I’m only about 1 month into rails so if I’m missing something extremely elementary you’ll have to forgive me.

  • 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-03T07:38:19+00:00Added an answer on June 3, 2026 at 7:38 am

    My guess is that the problem lives in this code

    def out_of_calibration(equipment)
        @equipment = Equipment.where("calibration_date <= ?", Date.today)
        mail(:to => "markaodonnell@gmail.com", :subject => "Equipment is out of calibration")
      end
    

    You are not using the argument that is passed in to that method AT ALL.

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

Sidebar

Related Questions

I have a Rails application (Rails 3.0.10) where users can have many articles, and
I have this rails Application which uses salesforce App. I want to know if
I have a non-rails application that I want to use rails active-record migrations with.
I have a Rails application that works with mongodb. I want to deploy it
I have basically a bare-bones rails 3.1 application that I want to deploy to
I have a rails application, and I authenticate users to the application using Devise.
I am new to Rails. I have my rails application and now I want
I have just inherited a medium sized Rails application and I want to try
I'm building Rails application and I want to have user registration/login functionality. I also
I have a simple Rails application I want to deploy to Heroku. When I

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.