eval - Ruby: How to use generate HTML with dynamic values? -
I am writing a ruby script which will generate a big flat HTML menu for my website, I can fly this menu But every time a page loads, I think that doing so is a waste of resources, especially when it will almost never need to be changed.
I want to effectively do the following (in semi-Sudoku):
part_of_my_menu = eval% {& lt; Script type = "text / javascript" & gt; Var Mapper = New Array (); & Lt;% parent_categories.each_with_index | Parent_category, i | -% & gt; Mapper ["# {parent_category.name}"] = & lt;% = i -%>; & Lt;% end -% & gt; & Lt; / Script & gt; } and then part_of_my_menu be able to type the string variable in an HTML file (I can do it).
I know that Ruby but does anyone know how it can achieve the same "cover" functionality? (PHI - I want to wrap my "AQUAL" function, this code is too high, I am posting just a small snippet to teach it that I am trying to achieve Am)
Thank you!
is part of the standard library so that you can work like this:
tmpl =% q {& lt; Script type = "text / javascript" & gt; ... & lt; / Script>} erb = ERB.new (tmpl) parent_categories = [...] part_of_my_menu = Erb.result There are some good examples of using this in the documentation.
You can use standard existing libraries and your existing knowledge, to build the rolled eval .
Comments
Post a Comment