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. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
@today = @total_running.to_i / days On 10/11/07, new_rails-ny <adam.DC-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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. > > > > >-- http://www.bdcsoftware.com" - Automotive CRM --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Oct 11, 4:17 pm, "Rafael Szuminski" <raf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> @today = @total_running.to_i / days > > On 10/11/07, new_rails-ny <adam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > 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. > > --http://www.bdcsoftware.com" - Automotive CRM--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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....> > Thanks again. > > > The other thing about this > > On Oct 11, 4:17 pm, "Rafael Szuminski" <raf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> @today = @total_running.to_i / days >> >> On 10/11/07, new_rails-ny <adam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> >> >>> 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. >> >> --http://www.bdcsoftware.com" - Automotive CRM > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---