bishop3000
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:
In the Mailer, I have:
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
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.