Thanks for the explanation. I have a dirt-simple workaround: Put the  
tag on one line and the ruby on the second. Here's what I did:

   %td{:class => @row_class}
     = check_box_tag :approved, 1, post_list_row.approved, {:onclick  
=> "new Ajax.Request('#{url_for(:controller => 'posts', :action =>  
'toggle_approved', :id => post_list_row[:id])}')"}

Sill not the most delightful looking code but it runs :)

Would attribute hashes work here? I.e.:

%td{:class => @row_class}= check_box_tag :approved, 1,  
post_list_row.approved, ajax_toggle_code(post_list_row[:id])

-- and --

def ajax_toggle_code(row_id)
   {:onclick => "new Ajax.Request('#{url_for(:controller =>  
'posts', :action => 'toggle_approved', :id => row_id)}')"}
end

What do you think?

On Mar 24, 2007, at 8:02 PM, Nathan Weizenbaum wrote:

>
> I have good news and bad news. The good news is that I figured out
> Steve's problem. The bad news is that it's practically unfixable.
>
> Steve, the issue is with the Haml tag-matching Regex. Because Regexes
> don't have the capability to understand the balancing of characters  
> like
> parentheses or, in this case, curly braces, once the Regex sees the
> first "{" that opens the attributes hash, it just goes on until it  
> sees
> the last "}" in the entire line. That means that if you have an
> attribute hash for the tag and a hash in the value, your tag will  
> break.
>
> There are a few ways around this. The best would be to put the
> check_box_tag call into a helper; this also results in a more readable
> template, so it's what I would advise.
>
> This is definitely a bug, but likely one that won't be fixed any time
> soon. I believe eventually Ruby's Regexes will become more  
> powerful, and
> able to support balancing, but until then Regexes just can't do  
> this and
> implementing a pure-Ruby information extractor without them would be
> prohibitively slow. So, unfortunately, the only solution is to not use
> brackets there.
>
> - Nathan
>
> Genevate wrote:
>> I'm having the saem issue trying to do somehting very similar.
>>
>> %a{:href=>
>> "javascript:void(0)", :onclick=>"event_toggle_occurrences(#{event.id,
>> url_for(:action => "occurrences", :id =>  
>> event)});", :title=>"Click to
>> view all occurrences"}
>>
>> Any luck with this?
>>
>> Chris-
>>
>>
>> On Mar 9, 3:53 pm, "s.ross" <[EMAIL PROTECTED]> wrote:
>>
>>> The error message is:
>>>
>>> (eval):43:in `compile': compile error
>>> (eval):34: parse error, unexpected '=', expecting ')'
>>> _hamlout.open_tag("td", 1, nil, false, "", {:class => @row_class}=
>>> check_box_tag :approved, 1, post_list_row.approved, {:onclick =>  
>>> "new
>>> Ajax.Request('#{url_for(:controller => 'posts', :action =>
>>> 'toggle_approved', :id => post_list_row[:id])}')"}, nil, false)
>>>                                                                    ^
>>> (eval):34: parse error, unexpected ')', expecting kEND
>>>
>>> Extracted source (around line #12):
>>>
>>> 9:   %td{:class => @row_class}
>>> 10:     = post_list_row.posted_by
>>> 11:   %td{:class => @row_class}= check_box_tag :approved, 1,
>>> post_list_row.approved, {:onclick => "new Ajax.Request('#{url_for
>>> (:controller => 'posts', :action => 'toggle_approved', :id =>
>>> post_list_row[:id])}')"}
>>> 12:   %td{:class => @row_class}= link_to(pluralize
>>> (post_list_row.comments.count(:conditions => 'approved = 0'),
>>> 'comment'), :controller => 'comments', :action => 'list')
>>>
>>> Strange, huh?
>>>
>>> Steve
>>>
>>> On Mar 9, 2007, at 10:42 AM, Nathan Weizenbaum wrote:
>>>
>>>
>>>
>>>
>>>> I don't think it should be failing... what happens?
>>>>
>>>> - Nathan
>>>>
>>>> s.ross wrote:
>>>>
>>>>> I have a case where this works:
>>>>>
>>>>> %td{:class => @row_class}
>>>>>    = check_box_tag :approved, 1, post_list_row.approved,  
>>>>> {:onclick =>
>>>>> "new Ajax.Request('#{url_for(:controller => 'posts', :action =>
>>>>> 'toggle_approved', :id => post_list_row[:id])}')"}
>>>>>
>>>>> But this fails:
>>>>>
>>>>> %td{:class => @row_class}= check_box_tag :approved, 1,
>>>>> post_list_row.approved, {:onclick => "new Ajax.Request('#{url_for
>>>>> (:controller => 'posts', :action => 'toggle_approved', :id =>
>>>>> post_list_row[:id])}')"}
>>>>>
>>>>> I prefer the latter construct. Any reason it might be failing that
>>>>> I'm not seeing?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Steve
>>>>>
>>
>>
>>>
>>
>>
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to