Link to home
Start Free TrialLog in
Avatar of bishop3000
bishop3000Flag for United States of America

asked on

How to pass object from Controller method to Mailer method

I'm new to Ruby on Rails, and I'm trying to write a web service API. I'm creating a User instance in an Action Controller method, and then trying to pass that to a Mailer method.

In my Action Controller, I have:

  def send_email  
 
    user = User.find_by_ongrid_key params[:keycode]
    
    if user.blank?
      render :text => "#{params[:keycode]},\"Not Found\"", :status => :not_found, :content_type => "text/plain"
    else

      if user.email.present?
        UserMailer.welcome_email(user).deliver
        render :text => "email sent", :content_type => "text/plain"  
      else
        render :text => "#{params[:keycode]},\"Email Address is Blank\"", :status => :failed_dependency, :content_type => "text/plain"            
      end

    end

  end

Open in new window



In the Mailer, I have:

  def welcome_email(user) 
    
    @user = user  
    email_with_name = "#{@user.name} <#{@user.email}>"

    mail( 
          :to => email_with_name,
          :bcc => "bishop@ongrid.net",
          :subject => "This is the email subject"
          #:content_type => "multipart/alternative",
          #:parts_order => [ "text/html", "text/plain" ]
        )

  end

Open in new window


I'm getting the attached error when trying to run send_email with HTTP Get. I've googled for two hours and tried many variations.

The user object is successfully created in the Action Controller (I returned the user's email address to confirm).

Thanks!
error-page.html
ASKER CERTIFIED SOLUTION
Avatar of bishop3000
bishop3000
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial