rendering a html.erb in rails with javascript -
i create page , parts of layout files rendered. want render 1 of these rendered part again javascript code.
i want render these part again
<div id="dialog" title="bookmark folders" style="resize: both;"> <%=render "layouts/filetree.html.erb"%> </div>
it render function creates this:
<div id="accordion"> <% @user.folders.each |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 |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 execution there changes on "folders", want render part again see update.
you shouldn't attempt render erb javascript - it's not how it's done (not mention you'd have write erb parser , call server data anyway).
if on other hand, you're asking how issue render of template using javasript , replace old content new 1 then...
watch http://railscasts.com/episodes/205-unobtrusive-javascript, read rails 3 , rjs idea of how trigger content updates via javascript.
general idea is
- render initial full page
- trigger ajax call (either after time or manual user request) request rails application
- handle request , respond javascript script (the script content should contain functionality , content replace want)
Comments
Post a Comment