partials and render_to_string

John Merlino
Sun, 18 Sep 2011 17:11:29 -0000

Hey all,

This is my understanding of html and browsers. On the server, html is
plain text. When the browser sends request to server to fetch a
document, if the file is not already in html format, perhaps instead
in  an rb file, ruby or whatever the server-side language of choice
converts the file to html and sends it to the browser. But what if we
have a partial thats not included in the document that is fetched?
Does it remain on the server as plain text and, therefore, is not part
of dom tree and therefore cannot be manipulated by javascript? In
other words, if we try to modify a dom node via javascript that is in
a partial on the server not interpeted, then javascript compiler will
raise an exception of undefined object. Now one technique is to use
ajax, where a user clicks a link, javascript captures event, sends
request to the server via ajax, and ruby handles the request. Now if
the response is to send the object back to the browser, specifically
javascript in plain text, then our rails method would have something
like this: render :text => ret_object.to_json. Now what if that
returned object hash (that utlimately gets converted to json before we
send response back to client) included this: returned_object[:data]
[:view] = render_to_string :partial => ''/home/my_table''.
Note that
my_table is  a partial in home directory. When we grab the response
via javascript, then we can stick it anywhere on the existing DOM
tree: $(''#my_table .my_content'').append(resp.data.view);. Now
that
data can be manipulated by javascript. Is this all correct?

1) My question is does that partial remain plain text on server until
it is explicitly loaded on the document that was fetched from server.

2) What exactly is the point of render_to_string? Why can''t we just
use "render"? Or do we need to use render_to_string in order to use
the jquery append method, for example, when appending it to the DOM?

thanks for response

--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org