#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    173
    Rep Power
    10

    Sending emails using ruby


    I am having some problems adding any ruby to an email.

    I have the following model

    Code:
    class MyMailer < ActionMailer::Base
    
      def mail(email)
        @from = email[:from]
        @recipients = "graham@domain.com"
        @subject = "Enquiry Form"
        body(:body => @email)
      end
      
    end
    the following in myMailer/mail.html.erb

    Code:
    qwwefw wefg wrge gre gqe g
    eqe <%=@body.body=>
    and i pass in a form results object to the mailer in view

    however this is the email i get from that template as displayed on the mongrel command line.

    Code:
    Sent mail:
     To: graham@domain.com
    Subject: Enquiry Form
    Mime-Version: 1.0
    Content-Type: text/plain; charset=utf-8
    
    qwwefw wefg wrge gre gqe g
    eqe  @body.body =>
    As you can see for some reason the view is removing the beginning <%= meaning that it wont parse that can anyone tell me what would cause it to be removed before sending the email. I am relatively new to ruby so any help would be appreciated.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    Constant Limbo
    Posts
    989
    Rep Power
    363
    You have teh wrong closing tag
    Code:
    irb(main):001:0> require 'erb'
    => true
    irb(main):002:0> tmplt1 = "Some text <%= $value =>\n"
    => "Some text <%= $value =>\n"
    irb(main):003:0> tmplt2 = "Some text <%= $value %>\n"
    => "Some text <%= $value %>\n"
    irb(main):004:0> t1 = ERB.new(tmplt1)
    => #<ERB:0xb7f44f40 @src="_erbout = ''; _erbout.concat \"Some text \"; _erbout.concat \" $value =>\\n\"; _erbout", @filename=nil, @safe_level=nil>
    irb(main):005:0> t2 = ERB.new(tmplt2)
    => #<ERB:0xb7f42344 @src="_erbout = ''; _erbout.concat \"Some text \"; _erbout.concat(( $value ).to_s); _erbout.concat \"\\n\"\n_erbout", @filename=nil, @safe_level=nil>
    irb(main):009:0> $value = 42
    => 42
    irb(main):010:0> t1.run
    Some text  $value =>
    => nil
    irb(main):011:0> t2.run
    Some text 42
    => nil
    irb(main):012:0>
    I've bolded the relevant sections above

    Comments on this post

    • Joseph Taylor agrees
    True happiness is not getting what you want, it's wanting what you've already got.

    My Blog

IMN logo majestic logo threadwatch logo seochat tools logo