Reputation: 1841
Is there a way to insert a Rails loop within the jQuery append method without using a partial? Here's the code that I'm trying to implement:
$('#selector').append('<%=j @stuff.each do |item| %>test<%=j end %>');
I know that I can put the rails loop into a partial and call the partial in the append method - that code will work (I've tested it). But for the purposes of my application, I'd prefer to not call a partial in the append method.
Upvotes: 0
Views: 1093
Reputation: 76774
It's my understanding that js.erb
only works in the views
folder (not the asset pipeline
). This means you can't call this kind of erb code in the asset pipeline
If you're loading the js outside of the asset pipeline, why don't you try this:
#app/views/controller/your_js.js.erb
<% @stuff.each do |item| %>
$('#selector').append('<%=j item %>');
<% end %>
Upvotes: 1