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

3 Answers 3

2

Try render_to_string instead of just render

Sign up to request clarification or add additional context in comments.

Comments

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')) %>");

Comments

0

Try this:

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

2 Comments

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
@RAJ... why are you using raw or html_safe when you are rendering a partial?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.