List Info

Thread: - vs = for blocks?




- vs = for blocks?
country flaguser name
United States
2007-10-17 01:37:03
This has probably been asked before, but I can't find
anything on it(-,
and = aren't the best search terms  ). 

The documentation indicates that - evaluates the ruby
content but does not
output it, and that = evals and outputs. However to display
say a
form_tag, I have to do

- form_tag whatever_path do

If I use the = it causes it to render twice. Not only does
the duplication
seem screwy, but this seems to contradict what the docs
indicate should
happen with those two operators. What exactly is going on
here?

Thanks,
Steve


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Haml" group.
To post to this group, send email to hamlgooglegroups.com
To unsubscribe from this group, send email to
haml-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: - vs = for blocks?
country flaguser name
United States
2007-10-17 01:48:51
The issue is how form_tag creates it's output. You'll notice
in the 
Rails docs, it uses the RHTML equivalent of -, <%, as
opposed to the 
equivalent of =, <%=. This is because form_for outputs
directly to the 
buffer that's gathering the eventual Haml result string.
This is done as 
a side effect; you don't need to deal with its return value.
It so 
happens that it also returns the text it added, so that
using = causes 
duplication.

- Nathan

Steve wrote:
> This has probably been asked before, but I can't find
anything on it(-,
> and = aren't the best search terms  ). 
>
> The documentation indicates that - evaluates the ruby
content but does not
> output it, and that = evals and outputs. However to
display say a
> form_tag, I have to do
>
> - form_tag whatever_path do
>
> If I use the = it causes it to render twice. Not only
does the duplication
> seem screwy, but this seems to contradict what the docs
indicate should
> happen with those two operators. What exactly is going
on here?
>
> Thanks,
> Steve
>
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Haml" group.
To post to this group, send email to hamlgooglegroups.com
To unsubscribe from this group, send email to
haml-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: - vs = for blocks?
country flaguser name
Australia
2007-10-17 01:51:45
Steve,

You are passing a block when you use the 'do' keyword. When
you pass  
a block into form_tag, it writes directly to the page.

As an rhtml example (because I think Haml formatting might
get  
clobbered when I send this):

<% form_tag whatever do %>
	... fields, html, etc goes here
<% end %>

or,

<%= form_tag(whatever) %>
	... fields, html, etc goes here
<% end_form_tag %>

So if you see the way I've not-used and used = there
hopefully that  
will help clear things up.

Cheers,
Brad


On 17/10/2007, at 4:37 PM, Steve wrote:

>
> This has probably been asked before, but I can't find
anything on it 
> (-,
> and = aren't the best search terms  ).
>
> The documentation indicates that - evaluates the ruby
content but  
> does not
> output it, and that = evals and outputs. However to
display say a
> form_tag, I have to do
>
> - form_tag whatever_path do
>
> If I use the = it causes it to render twice. Not only
does the  
> duplication
> seem screwy, but this seems to contradict what the docs
indicate  
> should
> happen with those two operators. What exactly is going
on here?
>
> Thanks,
> Steve
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Haml" group.
To post to this group, send email to hamlgooglegroups.com
To unsubscribe from this group, send email to
haml-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: - vs = for blocks?
country flaguser name
United States
2007-10-17 10:12:17
On Tue, 16 Oct 2007 23:48:51 -0700, Nathan Weizenbaum
wrote:

> The issue is how form_tag creates it's output. You'll
notice in the 
> Rails docs, it uses the RHTML equivalent of -, <%,
as opposed to the 
> equivalent of =, <%=. This is because form_for
outputs directly to the 
> buffer that's gathering the eventual Haml result
string. This is done as 
> a side effect; you don't need to deal with its return
value. It so 
> happens that it also returns the text it added, so that
using = causes 
> duplication.
> 
> - Nathan

Thanks, I didn't realize that form_for output directly to
the buffer, and
I guess never even took notice of the fact that all of my
rhtml templates
used <% instead of <%=.

Thanks


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Haml" group.
To post to this group, send email to hamlgooglegroups.com
To unsubscribe from this group, send email to
haml-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )