How to automatically update boolean in database after a certain amount of time?
<p>so I've been setting up a website, Iv'e now implemented the "premium" membership which automatically re news every once a year with stripe. In my database, I have <code>business</code> as a boolean and <code>expires</code> as a string.</p>

<p>Here is my code for my SubscriptionsController:</p>

<pre><code>class SubscriptionsController &lt; ApplicationController

before_action :logged_in_user, only: [:new, :create]

def new
end

def create
    token = params[:stripeToken]
    customer = Stripe::Customer.create(
        card: token,
        plan: 1,
        email: current_user.email,
        )

    current_user.business = true
    current_user.stripeid = customer.id
    current_user.expires  = 1.year.from_now
    current_user.save       #Create a one year from now expiry, when date == expires current_user.business = false

    flash[:success] = "You've successfully subscribed, you have been charged $159."
    redirect_to current_user #Add redirect to dashboard once implemented
end

def update
    @user = User.find_by(:id)
    if Time.now &gt;= @user.expires
        @user.business = false
    end
end

def logged_in_user
  unless logged_in?
      store_location
      flash[:danger] = "Please log in to view this page."
      redirect_to login_url
  end
end 
end
</code></pre>

<p>Essentially, what I would like to do is what I made in my <code>def update</code>, however I know that won't work. But maybe there is a way to make an argument like this in my database?</p>

<p>Database I'm using is <code>postgresql</code><br>
Payment processor is <code>stripe</code><br>
User model/authentication system is <code>custom</code> and not <code>devise</code>  </p>

<p>Thanks everyone :)</p>