Is there any standard or emerging standard to document the parameters that can be passed into a Rails partial ?
When _my_partial.html.erb expects a title and an elements local var passed with render 'my_partial', title: t, elements: e, there must be a common way to document their names, expected types and roles, without reading the whole partial code. Something like RDoc or Tomdoc for methods and classes. Isn’t there ?
Edit: I’ve found a post whose author advocates initializing parameters with <% var ||= 'default_val' %> in the first lines of the partial, which is indeed a safe practice and a kind of in-code doc. Is there really no comment/parameter-declaration solution for this ?
At the beginning of your partial, simply call all the variables that are referenced.
Reasons why this is good for your project:
The practice of using
<% var ||= 'default_val' %>is actually unsafe because it allows bugs to hide. You want your code to immediately blow up the moment something isn’t done right. And if these variables should be passed, then you want the code to blow up when they’re not there.