chell
chell

Reputation: 7866

how to add images to Rails email with full url path

I want to add images to an email template but don't want to add them inline but with the full path to their location on the server where the application is hosted.

How can I do this in Rails 3 action mailer?

Upvotes: 0

Views: 2114

Answers (1)

Muhammad Sannan Khalid
Muhammad Sannan Khalid

Reputation: 3137

in your controller action

def example_action
 UserMailer.notifier(request.protocol, request.host_with_port).deliver
end

add below in your user_mailer class

def notifier(protocol, host)
    @protocol = protocol
    @host = host
    mail(:from => "[email protected]", :to => "[email protected]", :subject => "Ur nice image path")
end

in your notifier.html.erb view.

<%= image_tag("#{@protocol}#{@host}/images/image_name.xxx")%>

Upvotes: 3

Related Questions