Simple division problems... I know horrible!

Hey all,
Thanks for your time here but I am having problems with something
that should be so simple…

@campaigns = Campaign.find(:all, :conditions => [“end_date >= ?”,
Date.today])
@total_running = Campaign.sum(:impressions, :conditions => ["end_date

= ?", Date.today])
for campaign in @campaigns
campaign_days = campaign.end_date - campaign.start_date
days = days + campaign_days
end
@today = @total_running / days

So as you can see I am running two simple queries and returning
variables to the view to be displayed. Unfortunately the last line of
code here is not working and I am at a loss. When I display @today it
is giving me the values of total_running and days with a / in the
middle as if these were just strings when actually I would like the
value for total_running to be divided by days.

Example of what is displayed -
123456/51

what I would like displayed -
2420

I have tried to change the / to a + and it did correctly add the
values together and display the sum of the two values so I am at a
loss as to why it will not divide the numbers.

Thanks for the assistance.

@today = @total_running.to_i / days

On 10/11/07, new_rails-ny [email protected] wrote:

    campaign_days = campaign.end_date - campaign.start_date

Thanks for the assistance.


http://www.bdcsoftware.com" - Automotive CRM

That did it, but I had to change both variables to “to_i” any reason
why I would have to do this for division but not addition? That is
what really through me for a loop.

Thanks again.

The other thing about this

That did it, but I had to change both variables to “to_i” any reason
why I would have to do this for division but not addition? That is
what really through me for a loop.

irb(main):001:0> “12” + “34”
=> “1234”
irb(main):002:0> “12” / “34”
NoMethodError: undefined method `/’ for “12”:String
from (irb):2
irb(main):004:0> “12”.to_i + “34”.to_i
=> 46

There is a + method for strings. But not a ‘/’ method. So while it
worked, odds are it wasn’t what you wanted…