title: Actionmailer for Appove Account - Email Not Send
body: <p>I'm trying to create an email which is sent when admin click to active account for user</p>
  
  <p>user has_one :account and account belongs_to :user</p>
  
  <p>in user.rb</p>
  
  <pre><code>devise :database_authenticatable, :registerable, :Trackable, :rememberable, :recoverable
  attr_accessible :account, :email, :password, :password_confirmation, :account_attributes, :approved
  
  has_one :account
  
  end
  </code></pre>
  
  <p>in account.rb</p>
  
  <pre><code>class Account &lt; ActiveRecord::Base
  
    attr_accessible :address, :approved, :name
    belongs_to :user
  
  end
  </code></pre>
  
  <p>in accounts_controller.rb</p>
  
  <pre><code>def activate
    @accounts = Account.find(params[:id])
    @users = User.where(:id =&gt; @accounts.id)
    if (@accounts.update_attributes(approved: true)) &amp;&amp; (@users.update_all(approved: true))
     AccountMailer.activate_account(@users).deliver   
     redirect_to accounts_path
    else
     redirect_to accounts_path
    end 
  end
  </code></pre>
  
  <p>in account_mailer.rb</p>
  
  <pre><code>class AccountMailer &lt; ActionMailer::Base
    default :from =&gt; "kapanjadi@gmail.com"
  
    def activate_account(user)
      @users = user   
          @account = account.find_by_user_id(user)
      mail(:to =&gt; user.email, :subject =&gt; "Activation Account", :from =&gt; "kapanjadi@gmail.com")
    end
  end
  </code></pre>
  
  <p>in account_mailer/activate_account.text.erb</p>
  
  <pre><code>congratulation, your account is active now
  </code></pre>
  
  <p>setup_mailer.rb</p>
  
  <pre><code>ActionMailer::Base.smtp_settings = {
    :address              =&gt; "smtp.gmail.com",
    :port                 =&gt; 587,
    :domain               =&gt; "localhost:3000",
    :user_name            =&gt; "kapanjadi@gmail.com",
    :password             =&gt; "password",
    :authentication       =&gt; "plain",
    :enable_starttls_auto =&gt; true
  }
  </code></pre>
  
  <p>but an email not send to email user, and no error..
  these did not happened to any other action.</p>
  
  <p>Any suggestions as to what I am doing wrong? </p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>in accounts_controller.rb</p>
  
  <pre><code>def activate
    @account = Account.find(params[:id])
    @user = User.where(:id =&gt; @account.id)
    if (@account.update_attributes(approved: true)) &amp;&amp; (@user.update_all(approved: true))
     AccountMailer.activate_account(@user,@account).deliver   
     redirect_to accounts_path
    else
     redirect_to accounts_path
    end 
  end
  </code></pre>
  
  <p>in account_mailer.rb</p>
  
  <pre><code>class AccountMailer &lt; ActionMailer::Base
  default :from =&gt; "fauzieuy@gmail.com"
  
    def activate_account(user,account)
      @account = account
      @accounts = Account.find_by_user_id(user)
      mail(:to =&gt; user.email, :subject =&gt; "Activation", :from =&gt; "kapanjadi@gmail.com")
    end
  
  end
  </code></pre>
  
  <p>error </p>
  
  <pre><code>undefined method `email' for #&lt;ActiveRecord::Relation:0x3e7c720&gt;
  </code></pre>