ruby on rails - What are the variables accessible from user_mailer.html.erb? -
my user_mailer.rb:
class usermailer < actionmailer::base default :from => "notifications@example.com" def welcome_email(user) @user = user @url = "http://example.com/login" mail(:to => user.email,:subject => "welcome awesome site") |format| format.html end end end
and how user_mailer.html.erb looks :
<!doctype html> <html> <body> <%= yield %> </body> </html>
what can access in user_mailer.html.erb. need define environment variables can access here ?
i'm guessing took example here?
you can treat user_mailer.html.erb
view, , user_mailer.rb
controller. if you've defined instance variable @users
can use in mail. per example in link:
user_mailer.html.erb
<!doctype html> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="content-type" /> </head> <body> <h1>welcome example.com, <%= @user.name %></h1> <p> have signed example.com, username is: <%= @user.login %>.<br/> </p> <p> login site, follow link: <%= @url %>. </p> <p>thanks joining , have great day!</p> </body> </html>
you can use helpers, no reason hardcode url in that, instead use sign_in_url
(or whatever route have login path).
note in email should use something_url
rather something_path
(so root_url
etc.)
you should define variables in welcome_email
method:
def welcome_email(user) @user = user @time = time.now @slogan = "my app's slogan" ... mail(:to => user.email,:subject => "welcome awesome site") |format| format.html end end
Comments
Post a Comment