-
-
Save lucascaton/124421b621d9a9bb6a89 to your computer and use it in GitHub Desktop.
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
Rails::Generator::Commands::Create.class_eval do | |
def template(relative_source, relative_destination, template_options = {}) | |
file(relative_source, relative_destination, template_options) do |file| | |
# Evaluate any assignments in a temporary, throwaway binding. | |
vars = template_options[:assigns] || {} | |
b = template_options[:binding] || binding | |
# this no longer works, eval throws "undefined local variable or method `vars'" | |
# vars.each { |k, v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b } | |
vars.each { |k, v| b.local_variable_set(:"#{k}", v) } | |
# Render the source file with the temporary binding. | |
ERB.new(file.read, nil, '-').result(b) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment