On Thu, 2009-07-16 at 22:25 +0200, Älphä Blüë wrote:
> 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 = Houston | ydspgm = 562.77
> TotalOffense [ Row 2 | Team ID = 20 | Team = Oklahoma | ydspgm = 547.86
> etc. etc.
>
> So far, so good. I can at least see the data that I want.
>
> Now, I want to assign the Team ID and the ydspgm to variables that I can
> manipulate and use later on. Normally, I would think that I could do
> something like this:
>
> def calculate_tsos(model, datavar, teamvar, valvar)
> var = model.compiled_this_week.find(:all)
> var.each_with_index do |rows, i|
> teamvar[i] = rows.team.id
> valvar[i] = rows.__send__(datavar)
> puts "#{model} [ Row #{i} | Team ID = #{teamid[i]} | Team =
> #{rows.team.name} | #{datavar} = #{teamval[i]}"
> end
> end
>
> But I get a..
>
> undefined method `[]=' for 0:Fixnum
I don't understand the '0' portion of the error message but the
problem's not that you don't understand arrays. Try naming your arrays
something else, leaving your method parameters as is. That should get
you going down a productive path.
HTH,
Bill
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---