Skip to content

Instantly share code, notes, and snippets.

@erikzaadi
Created December 21, 2011 13:01
Show Gist options
  • Save erikzaadi/1505966 to your computer and use it in GitHub Desktop.
Save erikzaadi/1505966 to your computer and use it in GitHub Desktop.
Rest-ish render for Railway JS
load 'application'
restRender = use('restRender')
action 'fetchMeSomething', () ->
model = { something : 'else' }
restRender model
load('application');
restRender = use('restRender');
action('fetchMeSomething', function() {
model = { something : 'else' }
restRender(model)
});
publish 'restRender', (model, title = @actionName, view = @actionName) ->
if req.accepts 'application/json'
send { model }
else
render view, { title : title, model: model }
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