Uploading image in email in rails 4.0.0 -


i new ror. trying create simple application create , send emails attachment in rails 4.0.0. user should able embed image email. email being sent , image uploaded gets corrupted in process, recipient not able see it. can suggest solution problem?

code mailer :

class usermailer < actionmailer::base   default :from => "xyz@abc.com"        def registration_confirmation(user)     @user = user     attachments['rails.jpg'] = file.read('c:\ruby\mail\public\images\rails.jpg')     mail(:to => "#{user.name} <#{user.email}>", :subject => "image attachment")   end end 

try:

  def registration_confirmation(user)     @user = user     attachments['rails.jpg'] = file.read(rails.root.join('public\images\rails.jpg'))     mail(:to => "#{user.name} <#{user.email}>", :subject => "image attachment")   end 

edit:

following comment, guess problem image. check if rails.jpg image exists in yourrailsroot/app/assets/images, , try using:

file.read(rails.root.join('app/assets/images/rails.jpg')) 

or

file.open(file.join(rails.root, "/app/assets/images/rails.png")) 

or, if want keep in public, same thing changing route


Comments