On Sep 18, 7:40 pm, 7stud -- <[email protected]> wrote:
> > 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? > > According to railsguide: > > ... render_to_string. This method takes exactly the same options as > render, but it returns a string instead of sending a response back to > the browser. > > So render_to_string does not send a response back to the browser, while > render :text => '<div>hello world</div>" does send a response back to > the browser. > One addition to this: it depends if you are writing code in your controller on in a view. In a view, render just returns a string and you don't need render_to_string (I don't think it even exists). In a controller render sets the response body (and calling it a second time raises a doublerendererror), so if you need to manipulate the rendered content in anyway (e.g. stick it in a json document) then you need to use render_to_string Fred > -- > Posted viahttp://www.ruby-forum.com/. -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

