[英]rendering a html.erb in rails with javascript
I create a page and some parts of it are layout files that are rendered. 我创建了一个页面,页面的某些部分是呈现的布局文件。 However I want to render one of these rendered part again with javascript code. 但是我想用javascript代码再次渲染这些渲染部分之一。
I want to render these part again 我想再次渲染这些部分
<div id="dialog" title="Bookmark Folders" style="resize: both;">
<%=render "layouts/filetree.html.erb"%>
</div>
It render function creates this: 它的render函数创建了这个:
<div id="accordion">
<% @user.folders.each do |f| %> <h3 id="<%= f.folder_name%>" class="folderBar"><a href="#" class="folderName"><b id="folderName"><%= f.folder_name%></b> created <%=distance_of_time_in_words(f.created_at, Time.now)%> before</a></h3>
<div class="<%= f.folder_name.delete(" ")%>">
<%if f.docs.empty?%>
<b>-No document currently!-</b>
<%else%>
<% f.docs.each do |r|%>
<a href="<%=r.url%>" style = "color:#0066CC;"><%= r.title%></a><br/>
<b><%=r.url%></b><br />
<%= r.snippet%><hr/>
<%end%>
<%end%>
</div>
<%end%>
</div>
Because after some execution there are some changes over "folders", I want to render this part again to see the update. 因为执行完某些步骤后,“文件夹”有了一些更改,所以我想再次渲染此部分以查看更新。
You shouldn't attempt to render erb with javascript - it's not how it's done (not to mention you'd have to write yourself a erb parser and eventually call the server for data anyway). 您不应该尝试使用javascript 渲染 erb -并不是这样完成的(更不用说您必须编写自己的erb解析器并最终以任何方式调用服务器以获取数据)。
If on the other hand, you're asking how to issue the render of some template using Javasript and then replace old content with new one then... 另一方面,如果您要问如何使用Javasript 发布某些模板的渲染 ,然后用新模板替换旧内容,则...
Watch this http://railscasts.com/episodes/205-unobtrusive-javascript , read this Rails 3 and RJS to get the idea of how to trigger some content updates via javascript. 观看此http://railscasts.com/episodes/205-unobtrusive-javascript ,阅读此Rails 3和RJS以了解如何通过javascript触发某些内容更新的想法。
General idea is 总体思路是
Instead of rendering I did it AJAX way and update it on the page. 我没有渲染,而是以AJAX方式进行了渲染,并在页面上对其进行了更新。 Thanks for the answers but I did not use any of these. 感谢您的回答,但我没有使用任何这些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.