Skip to content

Instantly share code, notes, and snippets.

@mathias
Created November 13, 2012 23:52
Show Gist options
  • Save mathias/4069230 to your computer and use it in GitHub Desktop.
Save mathias/4069230 to your computer and use it in GitHub Desktop.
I don't do:
<%= javascript_tag do %>
window.posts = <%= @posts.to_json %>
<% end %>
I do:
<div id="posts" data-url="<%= @posts %>">
And the view is smart enough to know to call to_json on it, works for collections
Also:
def as_json
{} # returns a hash of filtered attributes of model
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment