This project is archived and is in readonly mode.
Incorrect binding used to render generator templates
Reported by Matt Gadda | November 29th, 2008 @ 07:17 AM
As of commit 5fa0457542b0ff541d0a80ff8c3561eec8e35959 (edge), Rails::Generator::Commands::Create appears to be passing the wrong binding to ERB.result.
- Create a custom generator derived from either Rails::Generator::Base or Rails::Generator::NamedBase
- Create a simple template and add the obligatory m.template() method call from manifest.
- Create a test method in your custom generator that excepts a block parameter and yields to that block somewhere in its body.
- Invoke that method from within the template and pass a block to it.
Note that although the method is callable, the block is never passed to the method on invocation. Any attempts to yield that block fail because &block is nil (whether implicitly or explicitly passed in). This is because the binding in which the template is rendered corresponds to the command, not the generator.
In my patch, I just provided for this case in Commands::Create.template() such that callers may pass in an optional :binding parameter. If passed in, template() uses the Generator binding and method invocations requiring blocks from within the template work fine.
Comments and changes to this ticket
-
Pratik December 22nd, 2008 @ 11:44 AM
- Assigned user set to josh
-
josh December 28th, 2008 @ 08:56 PM
- Milestone cleared.
- State changed from new to open
-
Repository December 28th, 2008 @ 09:14 PM
- State changed from open to resolved
(from [1f0aecd931a9292b52402143be979ab4c06f06cd]) Allow custom rails generators to pass in their own binding to Create command so that the corresponding erb templates get rendered with the proper binding [#1493 state:resolved] http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 1493 Incorrect binding used to render generator templates (from [1f0aecd931a9292b52402143be979ab4c06f06cd]) Allow c...