This project is archived and is in readonly mode.
render_to_string doesn't use :locals option
-
Frederick Cheung
- State changed from new to invalid
I just did a quick experiment and this seemed to work ok (on 2.2.2) . Can you construct a failing test/example to show exactly how it isn't working for you?
-
barunio
i thought maybe there was a change in rails 2.2 that would have made this work, but i just updated to 2.2.2 and this is still not working for me. here is some very simple code to demonstrate:
I have a ReportsController, with an view in the views/reports/ folder called "show.xml.builder"
In my controller:
x = render_to_string(:action => 'reports/show.xml.builder', :locals => {:blah => 'hi'})In the view:
puts blahI get a "undefined local variable or method
blah'" error (because the local variable is never defined for the view). -
Frederick Cheung
:locals only exists for render :partial
-
barunio
actually, locals is accepted when rendering a template as well as a partial - but not for rendering an action, apparently. as reference, from the api docs:
Renders the template with a local variable
render :template => "weblog/show", :locals => {:customer => Customer.new}
i did get render_to_string working with local variables when i render a template, which is fine for my needs. not sure what the logic is behind allowing locals for rendering a template but not an action...