similar to: Finding the position on an item in a collection

Displaying 20 results from an estimated 20000 matches similar to: "Finding the position on an item in a collection"

2006 Apr 03
2
Fast way of finding new position for model object?
I have a model object that acts as a list. The position of each object is determined by two factors: number of votes ascending and 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 =>
2007 Jul 25
5
editing multiple models in one form
Very new to this but would appreciate a hand as this is driving me mad, I''m trying to update both degree and assigned from a single form, the degree section updates fine but assigned just retains the same values, any help much appreciated! my edit.rhtml file looks like: <h1>Editing degree</h1> <%= error_messages_for :degree %> <%= start_form_tag :action =>
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/.
2007 Jul 03
5
HOW TO: Easily output alternating item styles via metaprogramming
I always need to apply alternating item styles when outputting a collection, here''s what I''ve been using recently. In the app helper I define this method: def alternate(items,alt=false items.map{|i| i.class}.each { |k| k.class_eval {attr_accessor :alt}} items.each { |i| i.alt, alt = alt, !alt } end When I call the partial I wrap the collection with this method:
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
2012 Jun 20
3
How to iterate over an array? (with a counter)
Given an array, I''d like to iterate over it with a counter to produce something like this from a template: foo.0 = ARRAYVALUE0 foo.1 = ARRAYVALUE1 foo.2 = ARRAYVALUE2 (where ARRAYVALUEn is replaced by the value, and the foo.n is incremented for each value) The puppet templates support iteration, but I don''t see how to also increment a counter to get the behaviour above? Is
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
2007 May 17
1
exec format error
Hi I have been using backgroundrb version 0.1 for a while. Unfortunately, I have to develop on windows :( It has worked fine for a while. However, this morning I started up and old app that worked fine and get this error. exec format error from running --trace I see that the error comes from backgroundrb_tasks.rb line 59 which reads: 59 `#{scripts_src}/start -d` Here is the context. desc
2007 Feb 14
1
cron like behaviour?
Hi I have previously used railscron for server-side manipulation of the database but had a heap of trouble working with it. BackgrounDRB was suggested to me by a friend. I upload some files via acts_as_attachment and these go lie in a dir structure that i desire. What I want from the background process is to periodically (not user initiated) do some file-structure manipulation i.e. I want to
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
2008 Jan 21
1
shared sessions and rails2
Hi all How would you go about sharing a session between two rails2 applications? I am using restful_authentication. A point in the direction of some relevant blogs would also be a great help. Regards Ivor --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group,
2007 Sep 26
3
Can't connect to local MySQL server
hello everyone, i am new to ROR. i am just trying to run a simple application which will show some data from database, i have done it in my local machine. But when i tried to do the same thing in my "Dreamhost" shared hosting. I got an error. i used the Rake tool and successfully migrated a model (using SSH client tool). The table was successfully created hosting db server, so i
2007 Sep 24
3
Oracle Date + RoR
Hi Experts, I''ve a model called Product where i''ve column called created_at, updated_at where i''ve made a query based on Oracle date format like date_of_created = ''23-SEP-07'' @product = Product.find(:all, :conditions => ["created_at=?", date_of_created]) but in view its empty. AND EXPERTS I''VE DATA WITH 24-SEP-07 FOR MORE
2007 Sep 10
2
form_remote_tag not providing params in Ajax
I''m new to Ruby, Rails and Ajax and I''m trying to do something seemingly simple. I am trying to use a value someone supplies in a form in another form that is dynamically generated using Ajax. I have the following code: <div id="race_table"> &nbsp; </div> <%= form_remote_tag(:update => "race_table", :url => { :action =>
2006 Sep 28
1
Autentication against BDC first
Hi all, I have this question, I ve got a master LDAP server on a remote place and i want to install a PDC and a BDC and a slave ldap server in other place. Mi question is... may I force de WorkStations logging (read the information )against the BDC first than PDC, so the READ trafic goes to the Slave Ldap??? The problem is the network avoid READ traffic. In the Samba FAQ recomends that the:
2009 Jul 16
9
Please help me understand how arrays are translated in rails
I''ve spent hours researching the subject and have tried many test sequences in IRB, and rails console but I''m just having trouble making headway into what is probably 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
2006 Apr 19
2
Ferret EOFError creating index
I''ve been messing around with Ferret (no punn intended). After spending some time testing it out (indexing to file), I decided to index about 10% of the data I want to eventually index. It took several hours to complete the index on my local machine, but it was created without any problems and after optimising it the searches returned results at the sort of speed I was expecting. I
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
2006 May 18
3
populating array of text_fields from an array of model objects
I have in my view the following: <% 0.upto(@num_performances) do |idx| -%> <%= text_field ''performance'', ''city'', :index => idx, %> <%= text_field ''performance'', ''venue'', :index => idx, %> <% end -%> and in my controller I have: @performance = [Performance.new("city" =>
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 missing?