I created an instance variable (@user) in the model of a mailer and want to access it in the view? But it’s giving me an an error (@user = nil). What’s the best way to pass a variable to view (the email body)?
Thanks, Chirag
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to access an instance variable in your mailer template then in your mailer model add
The above would create an instance variable @user that can be accessed in your view. You should be able to access user object in your mailer view by doing
The docs here have examples of alternative ways if you are using multiple formats (text/html).