How to use Haml in your helpers
You know those helper methods that just render some HTML but look weird because of
content_tag
s all over the place? You could also use Haml instead.Example
Consider the following helper.
That looks clumsy and is hard to read.
Wouldn't it be nicer to say something like this?
It would be, and you can have it, too. You simply need to define
render_haml
as a helper method:
Note how we pass the helper method's view context (
self
). This means that all of your other helper methods will be available to your Haml fragment.
Also note that you can pass locals to your Haml templates as usual:
E
No comments:
Post a Comment