each

Ruby on Rails: nested each loop within while loop generates error

那年仲夏 提交于 2019-12-13 06:01:56
问题 I get a syntax error, when I execute the following code within the rails console: "syntax error, unexpected $end, expecting keyword_end" range = 2 my_array = Array.new(range) a = [1] i = 0 while i < range do a.each do |b| puts "test" end i += 1 end Does anyone know what I am doing wrong? The strange thing is, that the code is working on my server within a ruby file. Thanks a lot! tuxware 回答1: If you're executing it in IRB, it's likely that, as Beerlington said, it's linebreak issues. It'd

show individual elements independently using each method

北城以北 提交于 2019-12-13 04:29:49
问题 trying to show only one element at a time using each function, but not sure how to get matching item associated with first item so as you hover over first "hoverMe" it shows only first showMe and so on here is what I have so far, I think I can do this a really messy way, but not sure if there is a clean way to do it. http://jsfiddle.net/Pm2vP/ <p class="hoverMe">Hover me<span class="showMe">show me</span></p> <p class="hoverMe">Hover me<span class="showMe">show me</span></p> <p class="hoverMe

JQuery each function pause between non functional

↘锁芯ラ 提交于 2019-12-13 03:45:14
问题 This JQuery function should timeout to ensure that each item is delayed 8 seconds after the last. Thus producing a gallery where images fade in and out 8 seconds apart from each other. It doesn't work. Any ideas. function gallery() { var timeout = 0; $('.cornerimg').each(function() { setTimeout(function() { $(this).addClass('cornerimgfocus'); setTimeout(function() { $(this).removeClass('cornerimgfocus'); timeout += 8000; }, (timeout + 8000)); },timeout); }); } Marvellous 回答1: var $images = $(

How to filter articles within a attr href with each and find usage ? simple tag list

偶尔善良 提交于 2019-12-13 03:38:19
问题 I have got lots of div.articles and in that articles; i've got list of tags. I am trying hide article divs which don't got href = '#myFilter'. I have no problem with reaching to href, my problem is reaching it's parent() without creating jQuery conflict . Here is jsFiddle example to inspect. jQuery //trying to hide which don't got a href '#/news' var news = '#/news'; $('.article a').each(function() { var category = $(this).attr('href'); if ( category === news ) {//select only articles got #

Trying to combine two spans together with jQuery, need help looping/iterating

只愿长相守 提交于 2019-12-13 02:33:49
问题 I think this is a pretty noob question, but I've thought about it for many many hours straight now, and I just can't figure it out. I need to take this html code below and get the .project_name span & the .location span to merge into the same span. <ol id="projects" class="wide"> <li class="dontsplit" id="1234"> <a href="/projects/1234" class="thickbox dontsplit"> <span class='project_name dontsplit'>First Project Name</span> <span class='location dontsplit'>Combined with First Location</span

jQuery each loop to rename every instance of an ID

本秂侑毒 提交于 2019-12-12 20:49:54
问题 I have a page that is creating dynamically created rows in a table with an input with an ID "fixedRate" I am trying to rename each instance of the fixedRate id. This is only working for the first instance of the id with my current code. Here is the code: var amountRows = $("#billTasks > tr").size(); var i=1; $("#fixedRate").each(function(){ if (i == amountRows) { return false; } this.id = this.id + i; i++; }); The way I think the code should work is adding a 1,2,3,... at the end of the word

Is there an easy way to generate ordered couples in Ruby

江枫思渺然 提交于 2019-12-12 18:04:56
问题 I was wondering if there is something similar to the Range but not with integers but with ordered couples (x, y) . I am wondering if there is an easy way to do something like this: ((1,2)..(5,6)).each {|tmp| puts tmp} #=> (1,2) (3,4) (5,6) EDIT : Maybe I was not 100% clear in my question :) I'll try to ask it in a different way. If I had these couples: (3,4) and (5,6) I am looking for a way to help me generate: (3,4), (4,5), (5,6) if I had to exlpain it better : if the couples are (x,y)-> (x0

jQuery each returns [object Object]

久未见 提交于 2019-12-12 16:29:03
问题 My problem is that the html variable returns something like this: [object Object][object Object][object Object][object Object][object Object], instead of the elements. What should i do different? var html = ''; $.each(data.response, function(index, value) { var tr = $('<tr>'); var tr_data = '<td>asd</td>'; html += tr.data('trackinfo',value).html(tr_data); }); $(target).html(html); 回答1: That's because you're setting the data on the tr and then filling it with your html, but still concatinating

How Can I Correlate Logical Drives and Physical Disks using the WMI and Delphi?

丶灬走出姿态 提交于 2019-12-12 14:36:12
问题 I already have a long working on an application that can read information from Micro, some (most) failed more still missing some, I'm working with WMI and Delphi. The problem I'm facing is that I need to be listed units which belong to each HD, for example: HD1 has drive C:, D: and so on. thank you 回答1: To correlate the Logical Drives and Physical Disks you must use the Win32_DiskDrive class and the Win32_DiskDriveToDiskPartition, Win32_LogicalDiskToPartition ASSOCIATORS classes. Try this

jQuery function containing if's and .each() very slow in IE7

巧了我就是萌 提交于 2019-12-12 14:27:02
问题 I basically search for an element with specific data-attributes, so I loop through all of the elements with the class that might have those data-attributes. I loop with the jQuery each() function and already read and experienced that it is quite often pretty slow in IE7 or any other IE compared to the other common browsers like Firefox, Chrome or Safari. Maybe there's a better way to find these elements ?! $('body').on('mouseenter', '.course', function(){ var startday = $(this).data('start');