I have a database called "products" that has a field that uses hstore called data
.
At the moment, in my index.html.haml, I'm just looping through products and displaying their data
as a hash:
- @products.each do |product|
=product.data #THIS PRINTS A HASH
%hr
Which, for example, could print a hash like:
{"Name"=>"Example","type"=>"book", "price"=>"7.99"}
I'd like to make a HTML table that could hold a dynamic number of keys and values, and print them into columns with values corresponding to keys. Here's a diagram:
Thanks for all help!
Hope this can help:
Solution 1: based on same .data content # Deprecated
Conditions:
The code:
This code will render properly if each
product.data
has the same amount of key/value pairs AND stored in the same order.Solution 2: fully dynamic (.data varying) # Recommended
Conditions:
The code:
Feel free to ask for details, I feel like I just gave you a piece of code without any explanation...