1

So, i'm working with rails 3.2.13 and what i'm trying to do is render a partial and then append it to a div using jquery:

$("#notifications").append("<%=raw escape_javascript(render('layouts/notification')) %>");

what it does right now, is it appends it to the right div but it doesn't render the partial or anything, it just renders the rails code as a string.. I don't know what i'm doing wrong but i bet its something silly that i'm missing.

Any help would be appreciated thanks

RAJ
  • 9,697
  • 1
  • 33
  • 63
Josh Roberts
  • 95
  • 1
  • 8

3 Answers3

2

Try render_to_string instead of just render

Cody Caughlan
  • 32,456
  • 5
  • 63
  • 68
1

if its a regular partial(under the same view) then:-

$("#notifications").append("<%= escape_javascript(render(:partial => 'notification')) %>");

else

$("#notifications").append("<%= escape_javascript(render(:partial => 'layouts/notification')) %>");
Milind
  • 4,535
  • 2
  • 26
  • 58
0

Try this:

 $("#notifications").append("<%= escape_javascript(render(:partial => 'layouts/notification')) %>");
RAJ
  • 9,697
  • 1
  • 33
  • 63
  • no that didn't work either and something weird was happening too with that code cause i tried console.log after it and it didn't execute, buy when i took it out it did – Josh Roberts Aug 14 '14 at 17:33
  • @RAJ... why are you using raw or html_safe when you are rendering a partial? – Mandeep Aug 14 '14 at 17:38