Forum: Ruby on Rails Expose JavaScript partial to global namespace and call it?

F1e10cb9b924fadcb24fa87bab12f974?d=identicon&s=25 Tom Tom (tommaxwell)
on 2013-07-30 00:03
Attachment: _show.js.erb (607 Bytes)
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!
Bdf1f2ad97e7b9c9db1fa70e3cef48bf?d=identicon&s=25 bacrossland (Guest)
on 2013-07-31 03:52
(Received via mailing list)
On Monday, July 29, 2013 5:03:13 PM UTC-5, Ruby-Forum.com User wrote:

> => {:folder => @folder } %>" );
> 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


 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.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.