Torsten Schrör dijo [Sun, Feb 28, 2016 at 09:44:18PM -0800]:
> Hello engineerDave,
>
> thank for you quick response.
> But the convert from array to hash is not my problem.
>
> I try do write an global list.haml for all tables to reduce the code
>
> this is the list
> (...)
>
> an input a have an array of fieldnames an fields as an helper
>
> def header(table)
> h={'default'=>Array[Array['ID','id']]}
> h['customer']=Array[Array['Name','name'],Array['Kundennr','reference']]
> h['domain']=Array[Array['Name','name'],Array['Kunde',"customer.name"] ]
> @header=h[table]
> @header=h['default'] if !@header || @header.count==0
> end
>
> this works fine for normal fields(this meen fields in the table direct)
> but if i try do access to an referencetable this not works
> for instance domain.customer.name
>
> direcly in haml this works
>
> [email protected] do |d|
> #{d.id}
> #{d.customer.name}
>
> my problem is, that i find no syntax to handle this with a variable.
>
> %h=b[h[1]]
> -> this works only for fields in the table, references are empty
>
> do you have an idea?
Ahh, right, welcome to the wonderful world of metaprogramming ;-)
In Ruby, you can "send" a string to arbitrary object, that is, you can
call the method of the corresponding name. Take this as an example:
>> string = 'This is a string'
=> "This is a string"
>> queries = ['length', 'reverse', 'empty?' ]
=> ["length", "reverse", "nil?"]
>> queries.map {|q| string.send(q) }
=> [16, "gnirts a si sihT", false]
But be *very* aware that sending arbitrary strings to be called on an
object, specially if any user-defined data is involved, can become a
huge security liability.
--
You received this message because you are subscribed to the Google Groups
"Haml" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/haml.
For more options, visit https://groups.google.com/d/optout.