Expose JavaScript partial to global namespace and call it?

16 views
Skip to first unread message

Tom Tom

unread,
Jul 29, 2013, 6:03:13 PM7/29/13
to rubyonra...@googlegroups.com
Hi All,

I'm making a Rails app in which users have folders in which to organize
journal entries. I'm trying to load a partial into view that displays
D3.js visualizations based on the character count of each journal entry.
The JavaScript code and HTML inject properly, but I don't think the JS
is executing.

Show.js.erb looks like this:
$("#actual-right").append( "<%=j render :partial => 'contents', :locals
=> {:folder => @folder } %>" );

$("#jscripts").append("<%=j render :partial => 'show', formats: :js,
:locals => {:folder => @folder} %>");

The second line appends _show.js.erb with the rest of my JavaScript in
application.html.erb. The top line appends some HTML tags for D3.

I need to figure out how to execute the JavaScript so when a user clicks
the link to one of their folders, the HTML and JS are injected and the
graphs are drawn. Attached is my _show.js.erb file -- I have tried
wrapping all the D3 code in a function and calling it at the bottom, but
that didn't work.

Any advice would be appreciated!

Attachments:
http://www.ruby-forum.com/attachment/8638/_show.js.erb


--
Posted via http://www.ruby-forum.com/.

bacrossland

unread,
Jul 30, 2013, 9:51:36 PM7/30/13
to rubyonra...@googlegroups.com
 You can try wrapping your javascript function calls in a jQuery document.ready call. It'll fire off when the document object model is ready. 
Reply all
Reply to author
Forward
0 new messages