search for: each_with_index

Displaying 20 results from an estimated 97 matches for "each_with_index".

2006 Feb 28
6
Problem with select and each_with_index
Disclaimer: Ruby newbie at work Thought I was going so well. Wanted to produce a select box from an array constant, with the indices returned as values , and the array values used as the descriptions. Checked out Ruby RDoc and saw there was an each_with_index method and came up with: <%= select (''type'', ''typecategory'', Typecategory.each_with_index {|item, index| [item, index]} )%> Where typecategory is defined (in environment.rb) as [ ''A'', ''B'', ''C'', '...
2006 May 12
1
each_with_index. Can you start at a desired index position?
When using array.each_with_index how do you start at a desired index position? I can do it like this, but its not very clean and doesnt seem efficient : desired_index_start = 20 array.each_with_index do |value,index| next if index<desired_index_start end Thanks Chris -- Posted via http://www.ruby-forum.com/.
2006 Apr 03
2
Fast way of finding new position for model object?
...d age of object descending. When a user adds or deletes a vote I need to quickly update the associated model object''s position. Right now this is done with the following method: def update_position position = nil Bug.find(:all, :order => "votes_count DESC, id ASC").each_with_index{ |bug,i| if bug.id == self.id position = i break end } self.insert_at(position) end Basically, find all of the bugs in the order in which they''re wanted and then iterate through each until the new position of this bug is found. When it''s fou...
2006 Apr 19
2
Ferret EOFError creating index
...:/ruby/lib/ruby/gems/1.8/gems/ferret-0.9.0/lib/ferret/index/segment_merger.rb:338:in `each'' c:/ruby/lib/ruby/gems/1.8/gems/ferret-0.9.0/lib/ferret/index/segment_merger.rb:338:in `merge_norms'' c:/ruby/lib/ruby/gems/1.8/gems/ferret-0.9.0/lib/ferret/index/segment_merger.rb:334:in `each_with_index'' c:/ruby/lib/ruby/gems/1.8/gems/ferret-0.9.0/lib/ferret/index/field_infos.rb:130:in `each_with_index'' c:/ruby/lib/ruby/gems/1.8/gems/ferret-0.9.0/lib/ferret/index/field_infos.rb:130:in `each'' c:/ruby/lib/ruby/gems/1.8/gems/ferret-0.9.0/lib/ferret/index/field_infos.rb:13...
2009 Jul 16
9
Please help me understand how arrays are translated in rails
...a very easy subject. I understand arrays with at least 4 other languages but with Ruby I haven''t found a mental connection with how I can assign variables to arrays.. Take for example: def calculate_tsos(model, datavar, teamvar, valvar) var = model.compiled_this_week.find(:all) var.each_with_index do |rows, i| puts "#{model} [ Row #{i} | Team ID = #{rows.team_id} | Team = #{rows.team.name} | #{datavar} = #{rows.__send__(datavar)}" end end This will give me: TotalOffense [ Row 0 | Team ID = 5 | Team = Tulsa | ydspgm = 569.86 TotalOffense [ Row 1 | Team ID = 47 | Team = Hou...
2006 Jan 02
2
Getting Index When Using render :partial
...a web service to retrieve an array of results to a search and a render :partial to display those results to the user, while at the same time putting the results into the session. Is there a way for my _book.rhtml file to have access to the index of the result currently being displayed, like each_with_index makes available to its block? This would allow me to have the client pass back the index and pull the data from the session, thus assuring that the client hasn''t fooled with it. Thanks for any ideas! Sean ----- Sean McMains AIM: SeanMcTex http://www.mcmains.net/ruminations -------...
2006 Jan 02
3
Re: Getting Index When Using render :partial (Benjamin Stiglitz)
Thanks for the suggestion, Ben. This seems an excellent approach to the problem, except that I''d been under the impression that one could only call render once. If you call it multiple times as the each_with_index loop iterates, are the results just combined automatically? How does that work? Thanks! Sean ----- Sean McMains AIM: SeanMcTex http://www.mcmains.net/ruminations On Jan 1, 2006, at 11:44 PM, rails-request@lists.rubyonrails.org wrote: > Instead of using the :collection parameter to render,...
2007 Apr 18
2
Checking validity of NHS numbers
Hello I need to check that the NHS numbers in my database are valid. I''m storing them as ten-digit strings: the first nine are the identifier and the tenth is a check digit. There are four steps to calculating the check digit (from http://www.connectingforhealth.nhs.uk/systemsandservices/nsts/docs/tech_nn_check_digit.pdf): 1. multiply each of the first nine digits by a weighting factor
2008 May 21
2
Schedule write errors?
...(NoMethodError) The error occurred while evaluating nil.instance from /opt/local/lib/ruby/gems/1.8/gems/packet-0.1.5/lib/packet/packet_nbio.rb:57:in `write_and_schedule'' from /Users/joel/git/deathstar/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/whiny_nil.rb:35:in `each_with_index'' from /opt/local/lib/ruby/gems/1.8/gems/packet-0.1.5/lib/packet/packet_nbio.rb:51:in `each'' from /opt/local/lib/ruby/gems/1.8/gems/packet-0.1.5/lib/packet/packet_nbio.rb:51:in `each_with_index'' from /opt/local/lib/ruby/gems/1.8/gems/packet-0.1.5/lib/packet/packet_nbio.rb:...
2011 Dec 07
4
what is "private method `split' called for nil:NilClass" error??
Dear all, I have this line: <% $c_repo.split('','').each_with_index do |repo, i| %> in one of my template files and on the target node I''m getting this error: err: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template zmfs/zmfs_prob.erb: private method `split'' called for nil:NilClass Any idea what am I...
2008 Jan 18
1
Values broken converting from rails into javascript
...#39;s contents are changed. Basically i have a method that returns an array of arrays, where each array is of the form [name, number] I then iterate over the arrays, and substitute in the values out of the array - <%options_for_select(SubjectFamilyMember.options_for_select(["3"])).each_with_index do |option_tag, i| -%> $("subject_family_members[]").options[<%= i+1.to_i %>]=new Option(''<%= option_tag[0] %>'', <%= option_tag[1].to_i %>, false, false); <%end %> When i run this in the console (escaping the quotes), it seems to produce th...
2009 Apr 30
1
error with test:functionals
...)) end and this is my failure message: 1) Failure: test_should_create_artist(ArtistsControllerTest) [/Users/bonacode/Desktop/arteacesso-br/arteacesso/vendor/rails/ activesupport/lib/active_support/testing/core_ext/test/unit/ assertions.rb:51:in `assert_difference'' (eval):3:in `each_with_index'' /Users/bonacode/Desktop/arteacesso-br/arteacesso/vendor/rails/ activesupport/lib/active_support/testing/core_ext/test/unit/ assertions.rb:47:in `each'' /Users/bonacode/Desktop/arteacesso-br/arteacesso/vendor/rails/ activesupport/lib/active_support/testing/core_ext/test/u...
2007 Feb 28
3
[ win32utils-Bugs-8942 ] several typo in windows-pr.
...s-pr. Initial Comment: I found typo in windows-pr. Attached is a patch against windows-pr HEAD. I checked all windows-pr sources using following script. Thanks, -- class String def normalize self.downcase.gsub(/_/, "") end end ARGV.each do |file| defs = nil File.read(file).each_with_index do |line, i| case line when /(\w+)\s*=\s*Win32API.new\([^,]+?,\s*.(\w+)/ a, b = $1, $2 p ["Win32API", file, i + 1, a, b] if a.normalize != b.normalize when /(\w+).call\(/ next unless defs a = $1 p ["def/call", file, i + 1, defs, a] if a....
2011 Oct 10
6
Ruby on Rails sqlite3 ranking
I am making a browser-based game using ruby on rails and I am having trouble implementing a ranking system for my game. Each player has five skills: intelligence, creativity, strength, charisma and technological. I want the player to have a rank for each skill. The ranking I have in place right now gives the same rank if two players have the same amount of skill. SELECT COUNT(*) AS [rank] FROM
2006 Jul 20
11
3 columns
Hi all, Not really sure what to put in the title so hope people still open this! What I want to do is produce something like this Col1 Col2 Col3 data1 data2 data3 data4 data5 data6 data7 data8 data9 data.. data.. data.. data.. data.. data.. data-n data-n+1 data-n+2 I can get the data back from my db
2006 Apr 12
4
Binding Text Field/Areas to Array?
Hi, If I have @answers in my Controller, which is an array of Answer model objects which don''t exist in the DB yet... How do I bind a text_area helper in the View to each Answer? (I''m pre-filling some of the Answers with other data people need to verify before submitting and will insert on POST.) I''ve been able to get the textareas to render but not with the
2006 Aug 03
3
HELP: multiple select list in ror
Hi Search doesn''t seem to be working so my apologies if this has come up before. I have some simple code in a view that generates a multiple select: <select name="menu_select" size="5" multiple="multiple"> <% for m in Menu.find(:all) %> <!-- this needs to be abstracted in ror fashion --> <option value="<%= m.id %>"
2006 Apr 14
2
spot the error (I can''t, I''m new)
I have a form that I want to use to update multiple objects. In the controller, @grades = Grade.find(params[:grade].keys) @grades.each_with_index do |grade, i| grade.update_attribute(params[:grade][i]) end all_valid = @grades.inject(true) {|memo, c| c.valid? && memo } this doesn''t update the attributes as I would expect. (I would just use Grade.update(params[:grade].keys,params[:grade].values) but I can'...
2013 Jan 30
2
Installing fog -0.7.2 for CloudProvisioner
...in `build_extensions'' from /usr/lib/ruby/site_ruby/1.8/rubygems/installer.rb:180:in `install'' from /usr/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:297:in `install'' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `each_with_index'' from /usr/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:270:in `each'' from /usr/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:270:in `each_with_index'' from /usr/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:270:in...
2007 Aug 15
4
Is there a automatic counter variable?
Does ruby have anything where if I''m going through a do-while loop, or a "3.times" loop or "for product in products" where there''s a variable that will tell me which iteration of the loop I''m on? Instead of havign to declare my own counter = 0 and then increment it each time? Seems like something Rails would have... I can''t seem to find