Solved

How to pass object from Controller method to Mailer method

Posted on 2014-02-16
1
309 Views
Last Modified: 2014-02-16
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
0
Comment
Question by:bishop3000
1 Comment
 

Accepted Solution

by:
bishop3000 earned 0 total points
Comment Utility
Resolved. I didn't have 'name' in the schema for the User class. Only 'first_name' and 'last_name'.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now