Which set of quotations marks do I use when mixing ruby with javascript? -


i having trouble figuring out set of quotation marks appropriate image below load. #icon + part work put in sample image append , correct div referenced. i'm not able figure out how appropriate image loaded within src.

$(document).ready(function(){   alert('test');   <% if @iosapps %>   (var =0; < <%= @iosapps.length %>; i++) {     $('#icon' + i).append('<img src = "<%= @iosapps['+i+'].app_store_icon %>">');   }   <% end %> }); 

the error is: can't convert string integer

you should loop in ruby, not in javascript. can't freely mix these two. 1 executed on server, other in client's browser. it's important understand what.

this snippet should want (more or less).

$(document).ready(function(){   alert('test');   <% if @iosapps %>     <% @iosapps.each_with_index |ia, idx| %>       $('#icon<%= idx %>').append('<img src="<%= ia %>.app_store_icon ">');     <% end %>   <% end %> }); 

oh, , error you're getting:

@iosapps['+i+'] 

you pass string "+i+" index of array. array doesn't know how work that, raises error.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -