Solved

How to pass object from Controller method to Mailer method

Posted on 2014-02-16
1
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
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 viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

617 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