v2.1.0 - Show latest stable - 0 notes - Class: Rails::Generator::Commands::Create
template(relative_source, relative_destination, template_options = {}) public

Generate a file for a Rails application using an ERuby template. Looks up and evaluates a template by name and writes the result.

The <a href="/rails/ERB">ERB</a> template uses explicit trim mode to best control the proliferation of whitespace in generated code. <%- trims leading whitespace; -%> trims trailing whitespace including one newline.

A hash of template options may be passed as the last argument. The options accepted by the file are accepted as well as :assigns, a hash of variable bindings. Example:

  template 'foo', 'bar', :assigns => { :action => 'view' }

Template is implemented in terms of file. It calls file with a block which takes a file handle and returns its rendered contents.

Show source
Register or log in to add new notes.