runcode
runcode

Reputation: 3643

Rails action mailer javascript ,ruby mix with javascript?

i am using rails 3.2.8.

Following the tutorial on http://www.railsmine.net/2010/03/rails-3-action-mailer-example.html

but seems not working well.

seems having the problem to recognize the javascript that embedded within the ruby code

Code that I think cause the problems

def support_notification(sender)
  @sender = sender
  mail(mail(:to => "[email protected] <script type="text/javascript">
  /* <![CDATA[ */
  (function(){try{var      
  s,a,i,j,r,c,l=document.getElementById("__cf_email__");a=l.className;if(a)  
  {s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2) 
  {c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}
  s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})();/* ]]> */
  </script>",
  :from => sender.email,
  :subject => "New #{sender.support_type}")
end

Error prompted

app/mailers/notifier.rb:6: syntax error, unexpected tIDENTIFIER, expecting ')'
...ourdomain.com<script type="text/javascript">
...                               ^

app/mailers/notifier.rb:6: syntax error, unexpected tSTRING_BEG, expecting keyword_do or     
'{' or '('...m<script type="text/javascript">
          ...                               ^
 app/mailers/notifier.rb:8: syntax error, unexpected  tIDENTIFIER, expecting keyword_end
  ...nt.getElementById("__cf_email__");a=l.className;if(a){s='';r...
  ...                               ^

 app/mailers/notifier.rb:12: syntax error, unexpected ')', expecting keyword_end

Upvotes: 0

Views: 674

Answers (1)

Ahmad Sherif
Ahmad Sherif

Reputation: 6223

Probably there's an error in the mentioned blog JavaScript, it explodes near any email address, probably the code you want is the following:

def support_notification(sender)
  @sender = sender
  mail(:to => "[email protected]",
  :from => sender.email,
  :subject => "New #{sender.support_type}")
end

Upvotes: 1

Related Questions