At the beginning of your partial, just call all the referenced variables.
# _my_partial.html.erb <% title %> <--- first line of file <% elements[0] %> <h3><%= title %></h3> <% elements.each do |element| %> <p> etc ... </p>
Reasons why this is good for your project:
- it does not rely on comments or files without code.
- any project developer can quickly find out which variables are needed by looking at the top of the file in question.
- By invoking variables, you guarantee that the missing variable will throw an exception. Items
- are called with square brackets because we also want it to explode if it doesn't list, right?
The practice of using <% var ||= 'default_val' %> is actually unsafe because it allows you to hide errors. You want your code to explode immediately when something has not been done correctly. And if these variables must be passed, then you want the code to explode when they are not there.
source share