#379 Template Handlers pro
Sep 04, 2012 | 12 minutes | Views
Here I will demonstrate creating two template handlers. One for Ruby which is great for JSON or CSV formats. Another for interpreting Markdown which is useful for informational content.
- source codeProject Files in Zip (62.3 KB)
- mp4Full Size H.264 Video (29 MB)
- m4vSmaller H.264 Video (14.4 MB)
- webmFull Size VP8 Video (17.1 MB)
- ogvFull Size Theora Video (33.2 MB)
Does this make performance faster than erb or its all about how to make your own template? nice screen cast.
Ryan, you can use <<-RUBY instead to get highlighted heredoc in Textmate.
thanks for the tip! Also works nicely in Sublime Text 2
Thank you for doing RailsCasts and offering a pro subscription reasonably. May I ask if you could make a video about code formatting within either a template or on a page. Like the way GitHub or GitGist formats code?
Or the way you're doing it on your own site!
Do you mean like he does in #207? There is even a revised one.
Ryan, your approach with truly nested templates for JSON nicely circumvents some problems I've encountered with RABL.
This can also be used to extract a JSON paginator into a template which can then be used across different models.
Thank you, Ryan for this awesome Railscast!
Everything was great up till the end when you did that markdown erb hack.
I agree about tilt, it would make things much easier.
Ryan, in rails master .rb was renamed to .ruby:
register_template_handle accepts a glob of extensions, so instead of registering each template extension like:
you can do:
This is perfect. I needed to export some data as CSV, and all the previous go-by's I had seen built the CSV content in the controller. Yucky! This moves it out to the view template where it should be, and frees you up to make the respond_to handler look nice and pretty. Good work!
Ryan, there is one hidden bug in this episode.
You won't see any difference unless you try writing partials in Markdown. I'm on Rails 3.2.12.
Thanks for this.