Ramy
Ramy

Reputation: 21261

How to reference one model from inside another model?

I'm trying to send an event invitation to a user if they already exist in my system and a website invitation if the user (email address) isn't already in my system. Here's how I'm trying to do it:

  def self.lookup_and_send_emails(emails, msg)
    addresses = split_addresses(emails)
    addresses.each do |email|
      if Users.where(email: :email)
         SwapMailer.babysitter_request.deliver
      else
        #send the devise/website invitation
      end
    end
  end

but what this gives me is:

 uninitialized constant Event::Users

How can I reach my Users model from my Events model. I could move this to the controller but I'm trying to keep my controller "skinny".

Upvotes: 1

Views: 644

Answers (1)

JellyFishBoy
JellyFishBoy

Reputation: 1798

When you are utilising the model Class it is singular. The correct syntax is:

if User.where(email: :email)
  SwapMailer.babysitter_request.deliver
else
  #send the devise/website invitation
end

Upvotes: 2

Related Questions