Skip to content

Instantly share code, notes, and snippets.

@dylanjha
Created March 22, 2015 03:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanjha/fe4a8daf5f978139f2ea to your computer and use it in GitHub Desktop.
Save dylanjha/fe4a8daf5f978139f2ea to your computer and use it in GitHub Desktop.
Rake task to load erb
<%# Put this file in app/views/test.html.erb %>
<h1>Here is some html</h2>
<%= name %>
task :erb_example do
string = Rails.root.join("app/views/test.html.erb").read
name = "Example Name"
result = ERB.new(string).result(binding)
#>> "<h1>Here is some html</h2>\n\nhere is name"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment