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 8651857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:10:16+00:00 2026-06-12T14:10:16+00:00

Right now I’m building a call tracking app to learn rails and twilio. The

  • 0

Right now I’m building a call tracking app to learn rails and twilio. The app has 2 relevant models ; The Plans model has_many users. The plans table also has the value max_minutes.

I want it to make it so that when a particular user goes over their max_minutes, their sub account is disabled, and I can also warn them to upgrade in the view.

To do this, here’s a parameter I created in the User class

  def at_max_minutes?
    time_to_bill=0
    start_time = Time.now - ( 30 * 24 * 60 * 60) #30 days
    @subaccount = Twilio::REST::Client.new(@user.twilio_account_sid, @user.twilio_auth_token)
    @subaccount.calls.list({:page => 0, :page_size => 1000, :start_time => ">#{start_time.strftime("%Y-%m-%d")}"}).each do |call|
      time_to_bill += (call.duration.to_f/60).ceil
    end

    time_to_bill >= self.plan.max_minutes 

  end 

This allows me to run if/else statements in the view to urge them to upgrade. However, I’d also like to make an if/else statement where, if at_max_minutes? than the user’s twilio subaccount is disabled, else, it’s enabled.

I’m not sure where I would put that though in rails.

It would look something like this

  @client = Twilio::REST::Client.new(@user.twilio_account_sid, @user.twilio_auth_token)
  @account = @client.account
  if at_max_minutes?
    @account = @account.create({:status => 'suspended'})
  else
    @account = @account.create({:status => 'active'})
  end

BUT, I’m not sure where I would put this code, so that it’s active all the time.

How would you implement this code, for the functionality to work?

  • 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-12T14:10:17+00:00Added an answer on June 12, 2026 at 2:10 pm

    Instead of constantly computing the total minutes used in at_max_minutes?, why not keep track of a user’s used minutes, and set the status to “suspended” on the transition (when used minutes goes over max_minutes). Then your view and call code would only have to check status (you may also want to store status directly on user, to save API calls over to Twilio).

    Add to User model:

     used_minutes
    

    When every call ends, update minutes:

    def on_call_end( call )
      self.used_minutes += call.duration_in_minutes # this assumes Twilio gives you a callback and has the length of the call)
      save!
    end
    

    Add an after_save to User:

    after_save :check_minutes_usage
    
    def check_minutes_usage
      if used_minutes >= plan.max_minutes
        @account = @account.create({:status => 'suspended'})
      else
        @account = @account.create({:status => 'active'})
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I'm building a small app that imports data from a spreadsheet and
Right now, the label for my Activity has the name of the current Activity.
Right now, I have developed an android app that is available free on the
Right now, I have three models Post, Comment and User (using Devise ) associated
Right now I have some TabItems in my App which are implicitly styled. I
Right Now I am making a twitter app and I am Using IFTweetLabel. I
Right now I am working on an iOS app that needs NSFileManager but when
Right now I have an upload field while uploads files to the server. The
Right now, I have: RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L] to match any username at the
Right now when I run this it keeps clicking on the same button every

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.