Skip to content

Instantly share code, notes, and snippets.

@Sephi-Chan
Created April 27, 2012 12:56
Show Gist options
  • Save Sephi-Chan/2508970 to your computer and use it in GitHub Desktop.
Save Sephi-Chan/2508970 to your computer and use it in GitHub Desktop.
Data seeder
# `name` is a symbol used as a key of the object described by `prefix`.
# `template` is the name of the partial (from view/ and without the _).
# `locals` are the local variables accessible in the template.
def seed_data(name, template, locals, prefix = 'window.Seeds')
partial = { partial: template, locals: locals, handlers: [ :jbuilder ], formats: [ :json ] }
json = render(partial, locals)
key = "#{prefix}.#{name}"
code = "#{key} || (#{key} = {}); #{key} = #{json};"
javascript_tag { raw(code) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment