ruby on rails 3 - Generate dynamic hstore key calls in Prawn -


i have hstore column i'm using build table in prawn (pdf builder). data consist of records given month. since hstore, keys used change day day needs dynamic.

i need determine:

1 unique keys used month

i created helper find unique keys used in month. these used column headers.

 keys(@users_logs)  # returns array - ["xc", "pic", "mountain"] 

the table display users dutylog data month. testing...if explicitly call known hstore keys...the data displays correctly. but, since hstore...i wont know table column in production.

for testing, call known hstore keys...this creates prawn table row data per duty log.

@users_logs.map |dutylog|         [ dutylog.properties["xc"],            dutylog.properties["pic"],            dutylog.properties["mountain"]             ] end 

but, since hstore...i wont know keys call in production. so, need make above iteration dynamic.

i tried, without success, iterate on each dutylog entry, iterate on each unique key , output 1 "dutylog.properties[x]" call each key value...but, outputs array of key values. tried using send() in block, didnt help.

@users_logs.map |dutylog|    [ keys(@users_logs).each { |k| dutylog.properties[k] }.join(",") ] end 

any ideas on how make "dutylog.properties[k]" dynamic?

took head scratching...but turning out quit easy

this build rows prawn table

def hstore_duty_log_rows     [keys(@users_logs)] +      @users_logs.map |dutylog|         keys(@users_logs).map { |key| dutylog.properties.keys.include?(key) ? "#{dutylog.properties[key]}" : "0" }     end end 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -