Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Variable Scope in Mailers0:55 with Jason Seifer
Variables have different levels of access depending on where they are defined in an application. Let's dive a little deeper in to mailers and variable scope to find out more about how they work.
In Ruby there are different ways to access variables from
different points in the application.
The two that we're going to talk about right now are local variables and
A local variable is considered local to where it's being called.
In the mailer method we're about to write, if we assigned the to do list
to a variable called to do list, our mailer views would not have access to it.
If we add the at symbol in front of it it becomes an instance variable.
This makes it available to other methods in the class and
in the case of Rails mailers the mailer views as well.
Once we have variables defined we can access these in the mailer view templates.
When I define the at to do list instance variable in the mailer method I can
access it in the view just like I would a regular Rails layout,
and would have access to the to-do list's title and list items.
You need to sign up for Treehouse in order to download course files.Sign up