Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to pass object from Controller method to Mailer method

Posted on 2014-02-16
1
Medium Priority
?
349 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
ID: 39863792
Resolved. I didn't have 'name' in the schema for the User class. Only 'first_name' and 'last_name'.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
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.
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

971 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