I like the idea of separating functionality and this seems like the way of the future.
But I'm used to integrating javascript inside loops in an embedded language like Rails ERB or PHP, where I can use the ID of a particular object as a reference in the javascript.
Rails example:
<% @comments.each do |comment| %>
<div id="comment_<%= comment.id %>">
<%= comment.text %>
<% link_to_function "Reply", "$('comment_#{comment.id}').insert(\"#{escape_javascript(render :partial => "_form", :locals => {:comment => comment})}\", {position: 'bottom'});" %>
</div>
<% end %>
This isn't the only time I've ended up wanting to use Ruby methods inside javascript either. I may want to use constants, or call other ruby methods on an object inside a loop user.enabled?
or user.full_name
, or render partials with those objects, etc.
So how is this supposed to be accomplished if all the javascript is in another file or outside the loop? I get that you can iterate through a bunch of divs in javascript using CSS selectors, but this doesn't allow me to call ruby methods on objects.
What am I missing? Thanks!