Skip to content

Instantly share code, notes, and snippets.

@rwilcox
Created May 20, 2011 12:42
Show Gist options
  • Select an option

  • Save rwilcox/982816 to your computer and use it in GitHub Desktop.

Select an option

Save rwilcox/982816 to your computer and use it in GitHub Desktop.
show.js.erb
/* See this in action at: https://github.com/rwilcox/rails_js_representation/blob/master/app/views/todos/show.js.erb */
(function(){
var myobj = {
reallyDue: function() {
if (<%= @todo.new_record? -%>) {
alert("this is a new record");
} else {
alert("old record");
}
},
route: function() {
return '<%= todo_url(@todo) -%>';
},
clickDelete: function() {
$.ajax({
url: ajaxRoute(),
type : "DESTROY",
success: function(data, text) {
alert("deleted");
}
});
}
};
json_result = <%= @todo.to_json.html_safe -%>;
myobj = $.extend( myobj, json_result.todo );
return myobj;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment