forked from tower-archive/tower
-
Notifications
You must be signed in to change notification settings - Fork 0
rendering
Lance Pollard edited this page Apr 12, 2012
·
1 revision
- Templates
- JSON
- The Rendering Process
class App.PostsController extends Tower.Controller
index: ->
@render "index"
class App.PostsController extends Tower.Controller
show: ->
App.Post.find @params.id, (error, post) =>
@render json: post
show: ->
App.Post.find @params.id, (error, post) =>
@respondWith post, (format) =>
format.html => @render "show"
This will perform content negotiation, i.e. it will figure out what the mime type the browser prefers and run the corresponding responder method (for html, json, csv, etc.). Those methods then call the render
method.
show: ->
App.Post.find @params.id, (error, post) =>
@render "show"
Calling the render method directly forces a specific content type to be rendered. Here is the method signature:
render json: {hello: "world"}
render "show" # render action: "show"
render "posts/show" # render file: "posts/show"
render -> h1 "Hello World"
render text: "success", status: 200
This converts the render arguments into a normalized options hash.