Forum: Ruby Simple Mailer Switch Not Working

Posted by Nikhil Khullar (nikhilkhullar)
on 2013-01-31 09:19
Attachment: contact_us_mailer.rb (755 Bytes)
Hello,

Am a newbie to Ruby. Please help me find out why this snippet of code is
failing and picking up the first case always:

class ContactUsMailer < ActionMailer::Base
  default :from => "bot@spyders.in"

  def contact_us_email(name, message, purpose, email)
  @name = name
  @message = message
  @purpose = purpose
  @email = email
  content_type "text/html"

  case @purpose
  when 'android'
    mail(:to => 'admin@spyders.in', :subject => purpose)
  when 'marketing'
    mail(:to => 'admin@spyders.in', :cc => 'admin@spyders.in,
admin@spyders.in', :subject => purpose)
  when 'ios'
    mail(:to => 'iosmaster@gmail.com', :subject => purpose)
  when 'recruitment'
    mail(:to => 'admin@spyders.in', :cc => 'admin@spyders.in', :subject
=> purpose)
  when 'general'
    mail(:to => 'admin@spyders.in', :subject => purpose)
  else
    mail(:to => 'admin@spyders.in', :subject => purpose)
  end

  end
end


Regards !
Posted by Joel Pearson (virtuoso)
on 2013-01-31 09:55
Can you give a few examples of input? It's difficult to see where it 
goes wrong without following the data you're entering.

Why are you mixing together instance and local variables? For example, 
you're using @purpose and purpose interchangeably.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.