Rails '.js.erb' not rendering partial

爱⌒轻易说出口 提交于 2019-12-08 04:12:56

问题


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


回答1:


Try render_to_string instead of just render




回答2:


Try this:

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



回答3:


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


来源:https://stackoverflow.com/questions/25313911/rails-js-erb-not-rendering-partial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!