简体   繁体   中英

How can I get information into a hash, and format the output of this information in view?

example:

 % dl
  %dt Series:
  %dd 5GW00239

How can I do to show the beginning of the hash in the %dt and when you have the two points within the hash line under it and jump to show the "rest" in the %dd

I am assuming you have a hash that looks something like this:

series_hash = {"Series1:" => "5GW00239", "Series2:" => "ABCDEFG"}

If this is the case, then you need a HAML file like

- keys = series_hash.keys
- keys.each do |key|
    %dl
      %dt= key
      %dd= series_hash[key]

should result in

<dl>
    <dt>Series1:</dt>
    <dd>5GW00239</dd> 
</dl>
<dl>
    <dt>Series2:</dt>
    <dd>ABCDEFG</dd>
</dl>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM