Created
December 21, 2011 13:01
-
-
Save erikzaadi/1505966 to your computer and use it in GitHub Desktop.
Rest-ish render for Railway JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load 'application' | |
restRender = use('restRender') | |
action 'fetchMeSomething', () -> | |
model = { something : 'else' } | |
restRender model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load('application'); | |
restRender = use('restRender'); | |
action('fetchMeSomething', function() { | |
model = { something : 'else' } | |
restRender(model) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
publish 'restRender', (model, title = @actionName, view = @actionName) -> | |
if req.accepts 'application/json' | |
send { model } | |
else | |
render view, { title : title, model: model } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
publish('restRender', function(model, title, view){ | |
if (req.accepts('application/json')){ | |
send({ model }) ; | |
} else { | |
title = title || this.actionName; | |
view = view || this.actionName; | |
render(view, { title : title, model: model }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment