I am trying to update a column in my database if a book was created more than 25 seconds ago (when deploying, it will be 7 days ago, but I can't wait that long :)).
Models:
class Book < ActiveRecord::Base
attr_accessible :author, :date, :description, :order, :title, :user_id, :author, :status, :queued
belongs_to :user
end
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me, :user_id, :name, :bio
has_many :books
end
Controller:
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@book = Book.new
@books = Book.select("DISTINCT name, id") # Not used right now
@sequence = @user.books
@sequence.each do |book|
book.created_at >= 25.seconds.ago ? book.queued = false : nil
end
end
User show view:
<% @sequence.order("created_at DESC").where(:queued => false).each do |book| %>
Am I even close to getting this to work? What am I doing wrong? As you can see, I want to change the "queued" attribute to false after 25 seconds...
Edit
I've been told I need to use something like Heroku's Scheduler for this to work. Is there no way for this to update the database without something like that?