Processing ActiveRecord

Hi-

What I would like to do in the controller is select 2 rows from my DB
and manipulate those rows to be rendered in the view.

result = MyModel.find(:all, :limit => 2, :select => column) # Gives me
2 rows.
@view_stuff = result[0] - result[1] #Get error for not having method
'-'

Do I need to write a class method to manipulate the result set? Even
if the column type is of type float?

Is there a better approach here?

Thanks!

should be
result[0].column - result[1].column
i think

That's what I thought it would be too, then I get the following:

"undefined method `column' for -2268.0:Float"

Any ideas?

pete wrote:

That's what I thought it would be too, then I get the following:

"undefined method `column' for -2268.0:Float"

Any ideas?

On Jan 29, 2:23 pm, Thorsten Mueller <rails-mailing-l...@andreas-

just checked it like that:
foo=ShipmentDivisions.find(:all, :limit => 2, :select => :amount)

where ShipmentDivisions has a col "amount"
foo[0].amount - foo[1].amount works fine

your
result = MyModel.find(:all, :limit => 2, :select => column)

uses (at least as typed here) a var column which must be a string with a
col name
this you can't use like
result[0].column

you would have to use something like
result[0][column]

if you need variable col names here. otherwise just use
result[0].the_absolute_colname

AMAZING! That worked!!

Why do you have to do "result[0][column]" when column is a variable?

THANK YOU!!

Why do you have to do "result[0][column]" when column is a variable?

easy enough:
result[0] is an object and result[0].xxx calls a function of this object
all columns are defined as functions for ActiveRecord objects
but your column is a string, containing the column name. there is no
function column, since there is no column with that name
ActiveRecord::[] is just an alternative way to request the content of a
col in a slightly more flexible way, by handing over the name as a
string

Perfect, thanks again for your help with this!