In my controller I wish to return HTML inside a json response, which will then be inserted via jQuery inside a div, using .html().
my controller :
div_content = view_context.link_to "logout", logout_path, method: :delete + '<div class="
return render :json => {:success => true, :username => current_user.email, :div_content => div_content}
javascript :
$('#special_div').html(data.div_content)
This content is html encoded and so the HTML does not render. I know that I can convert the string using regular expressions or something, on the javascript side but it seems to make sense to not send it encoded from the server.
I found the more correct solution is to render a partial, which contains all the logic and formatting needed. This makes much more sense since in the partial you can use your template engine and such.