Hi Harald,
On Sep 28, 2009, at 4:09 AM, harald wrote:
> Thank you for your fast reply. I do not get this to work. Should it
> work?
> I have haml (2.2.3) installed if that make any difference?
>
>
> controller.rb:
>
> def func(hash)
> hash.each_pair do |key, val|
> puts "#{key} ->#{val}"
> end
> end
>
> view.haml:
>
> %p #{func({"animal" => true, "number" => 5})}
This view is asking for a p tag wrapped around the string
representation of the return value of func. As written, func returns
the input hash. Try something like this:
def func(hash)
hash.collect do |k, v|
"#{k} -> #{v}"
end.join("<br>")
end
It will return "animal -> true<br>number -> 5" for your sample input.
Rhett
>
>
> Returns:
>
> number ->5 animal ->true
> number5animaltrue
>
>
>
> On Sep 28, 4:33 pm, Nathan Weizenbaum <[email protected]> wrote:
>> I think the example you gave should work, but there are a few cases
>> where
>> the Haml parser will fail to parse Ruby interpolation. The
>> following, for
>> example:
>>
>> foo #{"bar}"}
>>
>> This is because Haml doesn't do any parsing of the Ruby code except
>> to try
>> to make sure brackets are balanced, so brackets within Ruby strings
>> will be
>> counted as Haml brackets. At some point, Haml may try to do some
>> basic Ruby
>> lexing to fix this in more cases, but that's pretty difficult to
>> get right.
>>
>>
>>
>> On Mon, Sep 28, 2009 at 12:56 AM, harald <[email protected]> wrote:
>>
>>> I have just start using haml but have some problems to understand
>>> how
>>> to escape a ruby hash.
>>
>>> like this one for example:
>>
>>> #{func({"animal" => true, "nummber" => 5})}
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---