views:

83

answers:

1

I heard that HAML has a capture function that can do something like Ruby on Rails's render_to_string, but can't find info on it. Actually, in View, we can use aString = render :partial ... and render actually works the same as render_to_string (as on Rail 2.2.2). But is there also an HAML way of doing it by capture?

A: 

Yes, you can capture the Haml buffer with capture_haml. You have to include Haml::Helpers in order to use it.

However, I am not sure if it works for capturing partials. From my understanding, I'd say that Haml is independent from render and thus, render_to_string or render :partial should also work for Haml.

At least, the following will work:

str = capture_haml do
  haml_tag "p#feedback.success", "Your request has been successful."
end

str # => "<p id='feedback' class='success'>Your request has been successful.</p>"
duddle