Topic: How does render_to_string work?
class MagazineController < ApplicationController
layout nil
def index
end
def viewer
@pages = Page.all(:order => 'number')
@pagedata = render_to_string(:json => @pages)
end
endI want to use @pagedata in the viewer view (/app/views/magazine/viewer.html.erb):
<script type="text/javascript" charset="utf-8">
var pageset = <%= @pagedata %>;
</script>With the @pagedata line commented out in the controller, I can point the browser at localhost/magazine/viewer and see the "viewer" view rendered, although the @pagedata variable obviously hasn't been rendered.
When I uncomment the @pagedata line, pointing the browser at the same address prompts me to download a file that contains the correct JSON.
I don't want to download it. I want it in that variable, written to the page.
What am I doing wrong?
Last edited by wintermute (2010-11-25 12:45:40)