mjc
mjc

Reputation: 3426

render_to_string stripping markup

I am using render_to_string within a JSON 'render' response. The render_to_string method seems to be striping my HTML, what am I doing wrong here?

Here's a sample:

render :json => {:html => render_to_string(:partial => 'view', :locals => { data => @data} )}

The response is coming through without any markup on it.

Upvotes: 0

Views: 2345

Answers (1)

arnklint
arnklint

Reputation: 41

Have you tried setting the template format in the respond_to block like this:

format.json do
  @template.template_format = :html
  @html = render_to_string( :partial => 'view', :locals => { data => @data}  )
  render :json => { :success => true, :html => @html }
end

Upvotes: 4

Related Questions