Skip to content

Instantly share code, notes, and snippets.

@rxgx
Last active January 2, 2016 12:59
Show Gist options
  • Save rxgx/8307295 to your computer and use it in GitHub Desktop.
Save rxgx/8307295 to your computer and use it in GitHub Desktop.
Embed JSON on page with ActiveModel::Serializer
module ApplicationHelper
def json_for(target, options = {})
options[:scope] ||= self
options[:url_options] ||= url_options
target.active_model_serializer.new(target, options).to_json
end
end
<div id="articles" data-articles="<%= json_for @articles %>">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment