I'm developing a site like the infamous Woot in a single particular way: I must rotate through items for a price of 1 daily. I'm using RoR, and would rather dynamically select a product, without having to enter one every day. Here would be the needs:

1) Customize the product every day
2) Choose dynamically from the table
3) Make certain to not choose exactly the same product two times

Thats about this. Within the items table, I presently possess a boolean known as listed that will mark when the product continues to be listed. My real question is, must i run some type of database job to select an item for your day or perhaps is there a way I'm able to like hash the date and develop an id the application displays before the date changes.

Just time.

Personally, I'd make it simple and go the scheduled job approach. To become more specific, I'd most likely make use of the whenever jewel to wrap a cron-job that runs once daily at night time. After that you can setup a technique inside your Product model to choose the present 'Product from the Day'.

Something similar to this will work:

product.rb

class Product < ActiveRecord::Base
  # Return the current product of the day
  def self.product_of_the_day
    self.find_by_listed(true)
  end

  # Set up the product of the day
  def self.setup_product_of_the_day
    current_product = self.product_of_the_day

    product_ids = self.all(
      :select => "id",
      :conditions => ['id != ?', current_product.id]
    )

    next_product = self.find(product_ids[rand(product_ids.length)])

    current_product.update_attribute(:listed, false)
    next_product.update_attribute(:listed, true)
  end
end

schedule.rb

every 1.day do
  runner "Product.setup_product_of_the_day"
end