Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8682325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:44:40+00:00 2026-06-12T21:44:40+00:00

Possible Duplicate: undefined method `to_f' for #<ActiveRecord::Relation:0x472d0a0> I’m trying to make a call tracking

  • 0

Possible Duplicate:
undefined method `to_f' for #<ActiveRecord::Relation:0x472d0a0>

I’m trying to make a call tracking application to learn twilio and rails.

Right now, I would like to make a graph that shows a user how many phone calls a particular phone number gets per day.

The schema is user has_many phones has_many calls.

I try to make the graph by creating an instance method that counts the number of phones on a particular day, but when I try executing the code, I get the error :

SQLite3::SQLException: no such column: calls.placed_at: SELECT COUNT(*) FROM "calls"  WHERE "calls"."phone_id" = 44 AND ("calls"."placed_at" BETWEEN '2012-09-15 00:00:00.000000' AND '2012-09-15 23:59:59.999999')

I don’t quite understand the code I’m using for the instance method, and it’s probably calling the wrong column. Your help on this would be greatly appreciated.

Here’s the important part of my call model:

def total_on(date)
  calls.where(placed_at: date.beginning_of_day..date.end_of_day).count
end

Here’s how I’m counting the phone calls in my show view

<%= (1.month.ago.to_date..Date.today).map { |date| @phone.total_on(date).to_f}.inspect %>

Here’s how I define the @phone variable

@phone = Phone.find_by_id(params[:id]) 

Here’s my complete phone model (for schema reference)

# == Schema Information
#
# Table name: phones
#
#  id              :integer          not null, primary key
#  name            :string(255)
#  twilio_number   :integer
#  original_number :integer
#  user_id         :integer
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#

class Phone < ActiveRecord::Base

  attr_accessible :original_number, :user_id, :name, :twilio_number
  belongs_to :user
  has_many :calls, dependent: :destroy

  validates :name, presence: true
  validates :twilio_number, presence: true
  validates :original_number, presence: true
  validates :user_id, presence: true

  default_scope order: 'phones.created_at DESC'

  validate :check_phone_limit, :on => :create

  def check_phone_limit
    if User.find(self.user_id).at_max_phone_limit?
      self.errors[:base] << "Cannot add any more phones"
    end
  end

  def original_number=(value)
    num = value.to_s.gsub(/[^0-9+]/, "")
    write_attribute(:original_number, num.to_i)
  end

def total_on(date)
  calls.where(placed_at: date.beginning_of_day..date.end_of_day).count
end

end

Here’s my complete call model

# == Schema Information
#
# Table name: calls
#
#  id               :integer          not null, primary key
#  AccountSid       :string(255)
#  From             :string(255)
#  To               :string(255)
#  CallStatus       :string(255)
#  ApiVersion       :string(255)
#  Direction        :string(255)
#  FromCity         :string(255)
#  FromState        :string(255)
#  FromZip          :string(255)
#  FromCountry      :string(255)
#  ToCity           :string(255)
#  ToState          :string(255)
#  ToZip            :string(255)
#  ToCountry        :string(255)
#  CallSid          :string(255)
#  DialCallSid      :string(255)
#  DialCallDuration :string(255)
#  DialCallStatus   :string(255)
#  RecordingUrl     :string(255)
#  phone_id         :integer
#  DialCallMinutes  :integer
#  created_at       :datetime
#  updated_at       :datetime
#

class Call < ActiveRecord::Base
  attr_accessible :AccountSid, :From, :To, :CallStatus, :ApiVersion, :Direction, :FromCity, :FromState, :FromZip, :FromCountry, :ToCity, :ToState, :ToZip, :ToCountry, :CallSid, :DialCallSid, :DialCallDuration, :DialCallStatus, :RecordingUrl, :DialCallMinutes
  belongs_to :phone


  def self.create_from_incoming_call(params)

   user_phone = Phone.find_by_twilio_number(params['To']) #Finds the phone number in the database based on what phone Twilio is calling


    twilio_request_params = {
      :CallSid => params['CallSid'],
      :AccountSid => params['AccountSid'],
      :From => params['From'],
      :To => params['To'],
      :CallStatus => params['CallStatus'],
      :ApiVersion => params['ApiVersion'],
      :Direction => params['Direction'],
        :FromCity => params['FromCity'],
        :FromState => params['FromState'],
      :FromZip => params['FromZip'],
      :FromCountry => params['FromCountry'],
      :ToCity => params['ToCity'],
      :ToState => params['ToState'],
      :ToZip => params['ToZip'],
      :ToCountry => params['ToCountry']
      :phone_id => user_phone.phone_id

    }


    call = Call.new(twilio_request_params)
    call.save  
    return call

  end

  def Call.update_dial_call(params)

    twilio_request_params = {
        :DialCallSid => params['DialCallSid'],
        :DialCallDuration => params['DialCallDuration'],
        :DialCallStatus => params['DialCallStatus'],
        :RecordingUrl => params['RecordingUrl'],
      :DialCallMinutes => (params['DialCallDuration'].to_f/60.to_f).ceil
    }

    call = Call.where( :CallSid => params['CallSid'] ).first
    call.update_attributes twilio_request_params
    call.save

  end


end

I’ve been stuck on this for a while; any help would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:44:41+00:00Added an answer on June 12, 2026 at 9:44 pm

    Your call model uses the standard rails created_at, yet your query was using placed_at, which doesn’t exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Call to undefined method mysqli_stmt::get_result My web host has PHP 5.3.10 and
Possible Duplicate: jQuery Ajax always returns “undefined”? I'm trying to come up with a
Possible Duplicate: How to solve “call to undefined function domxml_new_doc()…” I'm using php5, when
Possible Duplicate: Undefined, unspecified and implementation-defined behavior I'm trying to deepen my understanding of
Possible Duplicate: Perl + POO and “Can't call method ”prepare I learned poo and
Possible Duplicate: Unable to do File Upload in PHP I am trying to learn
Possible Duplicate: error saying “autocomplete method doesn't exist” with rails3-autocomplete gem I am trying
Possible Duplicate: PHP Fatal error: Call to undefined function mssql_connect() I am developing a
Possible Duplicate: Undefined, unspecified and implementation-defined behavior I know calling delete on same object
Possible Duplicate: Could anyone explain these undefined behaviors (i = i++ + ++i ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.