Created by: gracewashere
Inspiration: http://thepugautomatic.com/2013/05/locals/
Problem:
It is idiomatic in Rails to use instance variables to pass data from controllers to views.
However, there are a number of disadvantages to this approach:
- If you mistype an instance variable in a view,
the application quietly swallows the error
and returns
nil
. - Instance variables can be set from anywhere in a controller, which can lead to spaghetti code and confusion about which variables are available for use in the view.
Solution:
By passing local variables explicitly to views, we can be more confident about the API between controllers and views.