Solved

How to pass object from Controller method to Mailer method

Posted on 2014-02-16
1
329 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
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…
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…

734 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