Suppose I have a Ruby ERB template named my_template.html.erb and it contains the following:
<div><%= @div_1 %></div> <div><%= @div_2 %></div> <div><%= @div_3 %></div>
Is there a way that I can programmatically display all available variables in a template?
For example, the following method:
def list_out_variables template = File.open("path_to/my_template.html.erb", "rb").read erb = ERB.new( template ) erb.this_method_would_list_out_variables end
will return something like:
['div1','div2','div3']
Any help would be greatly appreciated.
Thanks Mike
ruby ruby-on-rails erb
Mike g
source share