Guest User

Untitled

a guest
Aug 17th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. Why can't the block see my variable?
  2. post "/email/send" do
  3.  
  4. @recipient = params[:email]
  5.  
  6. Mail.deliver do
  7. to @recipient # throws error as this is undefined
  8. subject 'testing sendmail'
  9. body 'testing sendmail'
  10. end
  11.  
  12. erb :email_sent
  13.  
  14. end
  15.  
  16. post "/email/send" do
  17.  
  18. Mail.deliver do
  19. subject 'testing sendmail'
  20. body 'testing sendmail'
  21. end
  22.  
  23. erb :email_sent
  24.  
  25. end
  26.  
  27. recipient = params[:email]
  28. Mail.deliver do
  29. to recipient # 'recipient' is a local variable, not a method, not an instance variable
  30. ...
  31. end
  32.  
  33. Mail.deliver do
  34. to @recipient # throws error as this is undefined
  35. subject 'testing sendmail'
  36. body 'testing sendmail'
  37. end
  38.  
  39. Mail.new(
  40. to: @recipient,
  41. subject: 'testing sendmail',
  42. body: 'testing sendmail'
  43. ).deliver!
  44.  
  45. Mail.new(
  46. :to => @recipient,
  47. :from => '[email protected]',
  48. :subject => 'testing sendmail',
  49. :body => 'testing sendmail'
  50. ).deliver!
  51.  
  52. pry(main)> Mail.new(
  53. pry(main)* to: '[email protected]',
  54. pry(main)* from: 'me@' << `hostname`.strip,
  55. pry(main)* subject: 'test mail gem',
  56. pry(main)* body: 'this is only a test'
  57. pry(main)* ).deliver!
  58. => #<Mail::Message:59273220, Multipart: false, Headers: <Date: Fri, 28 Oct 2011 09:01:14 -0700>, <From: [email protected]>, <To: [email protected]>, <Message-ID: <[email protected]>>, <Subject: test mail gem>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>>
  59.  
  60. mail = Mail.new
  61. mail.to = '[email protected]'
  62. mail[:from] = '[email protected]'
  63. mail['subject'] = 'This is an email'
  64. mail.body = 'This is the body'
Add Comment
Please, Sign In to add comment