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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:06:09+00:00 2026-06-15T06:06:09+00:00

I have a Document model with a string column access and a User model

  • 0

I have a Document model with a string column access and a User model with a string column team. In a Document I can enter an array of items for access such as “staff, sales, manager”. Meanwhile, a User has only one item under team.

I am trying to send emails to specific Users based on whether or not for each user.team is included in the array for Document.access.

For example if Document.access = "sales, management", only Users with team = "sales" or team = "management" will be sent the email. Other Users such as team = “accounting” would not.


Update:

From what I gather on this question, It would appear ActionMailer cannot loop, so I have modified my document_observer. Now that I moved the loop portion out of the mailer, user.email is erroring out with

undefined method 'user' for

If I stick in a string like ‘joe@net.com’ the proper number of emails go out, so that part seems to work. Now it is a matter of passing the right email addresses to the message.

Relevant code from my document_observer below:

 def after_save(model)
   @users = User.all
   @users.each do |user|
     if model.access.include? user.team
       MultiMailer.doc_notification(model).deliver
     end
   end  
 end

Relevant code from mailer. How do I pass on user.email for each email?

def doc_notification(document)
  mail(:to => 'joe@net.com')
end

Latest Update:

Ok, I just switched a couple of lines to

MultiMailer.doc_notification(user).deliver

and

def doc_notification(user)

So now the email goes out to each of the right users, but it appears I am just reversing the problem above and trading unknown user for unknown document. The email needs to reference the URL for the document that was just updated..

I should also mention that there is no association between Document and User.

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

    The Answer

    From the document_observer

    def after_save(model)
      @users = User.all
      @users.each do |user|
        if model.access.include? user.team
          MultiMailer.doc_notification(model, user).deliver
        end
      end
    end
    

    From the mailer

    def doc_notification(document, user)
      @document = document
      mail(:to => user.email)
    end
    

    Credit goes to a very nice Nathaniel Talbott of Triangle Ruby Brigade who answered my question in person. I guess it helps to get out the house sometimes.

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

Sidebar

Related Questions

I have 2 model: class User include Mongoid::Document field :email, :type => String, :null
I have model: # encoding: utf-8 class Tag include Mongoid::Document field :name, type: String
I have three models: class User include Mongoid::Document field :name, :type => String has_many
I have following User model, embeds the Category model, class User include Mongoid::Document include
I have model: class Task include Mongoid::Document field :name, type: String field :category, type:
I have the model: class Action include Mongoid::Document field :name, type: String field :assignment_date,
I have the following model: class Entry include Mongoid::Document field :title, type: String field
I have a model: class SimpleAction include Mongoid::Document field :set_date, :type => Date and
i have the following code in the rails company model: class Company include Mongoid::Document
Currently I have tasked to prepare Document service for client side parser that user

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.