Created
April 27, 2012 12:56
-
-
Save Sephi-Chan/2508970 to your computer and use it in GitHub Desktop.
Data seeder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# `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