title: Send email to all users in rails
body: <p>I am trying to create a method that, when called send a email to all users.</p>
  
  <p>My ultimate goal is to call this method via a scheduler (i already got the scheduler working) And the method will go thought all users and send emails to some of then if some pre-requisites are met.</p>
  
  <p>Right now i just want to learn how i make a simplest stuff that is to send a custom email to every user in the table.</p>
  
  <p>My first issue is:</p>
  
  <pre><code>  def send_digest
      @users = User.all
      @users.each do |user|
        @time  = Time.now
        mail(to: user.email, subject: user.name)
      end
    end
  </code></pre>
  
  <p>This method (is inside app/mailer/user_mailer.rb) only is sending one e-mail to the guy with biggest ID in the table. Why that?</p>
  
  <p>Also, what i need to do to access the variable "user.name" inside the email? </p>
  
  <p>EDIT:
  There a better way for accessing user variable inside the mail body than doing @user = user?</p>
  
  <pre><code>  def send_digest(user)
      @time  = Time.now
      @user = user
      mail(to: user.email, subject: 'mail message')
    end
  </code></pre>