This project is archived and is in readonly mode.
render_to_string is completely broken
-
Pratik
- State changed from new to incomplete
Use render_to_string :template => 'i_do_not_exists/index'
What is the behavior in Rails 2.0.x ?
-
Jaroslaw Zabiello
I do NOT want to render just another template (without its action). I want to render another action. I have just checked and I see it is broken for RoR 2.0.2 and 2.1.0 as well. Therefore information displayed in api.rubyonrails.org is misleading and wrong (capitalization is mine):
render_to_string(options = nil, &block) Renders according to THE SAME RULES AS RENDER, but returns the result in a string instead of sending it as the response body to the browser.# app/views/controllers/my_controller.rb: class MyController < ApplicationController def index @slot = render_to_string :action => 'second' end def second @var = 'World' render :text => 'It will never be displayed from host/my!' end end # app/views/my/index.html.erb: Slot: <%= @slot %> # app/views/my/second.html.erb: Hello <%= @msg %>!Result at http://localhost:3000/my:
Result:
Slot: Hello !The @msg variable was not rendered at all. render :text was also ignored at all. It looks like render_to_string ignores Ruby code in the action.
-
Pratik
- State changed from incomplete to invalid
You cannot render another action. render_to_string is only for rendering templates. It will not call action code.