I
I
Ilya Bondarenko2014-07-07 08:07:22
Ruby on Rails
Ilya Bondarenko, 2014-07-07 08:07:22

How to change the status of a promotion at a certain time?

There is a Promo model and a table attached to it:

create_table "promo", force: true do |t|
    t.string   "name"
    t.text     "text"
    t.string   "image"
    t.boolean  "active"
    t.datetime "date",               limit: 255
    t.string   "image_file_name"
    t.string   "image_content_type"
    t.integer  "image_file_size"
    t.datetime "image_updated_at"
  end

In it , date is the date until which the promotion lasts. active flag, whether the action is currently active.
Now, on the main page, promotions are displayed if they are active and the current date is less than the end date.
I would like to make it so that when the end date is reached, the activity flag is automatically removed and the administrator is sent a message that the promotion has expired.
Please tell me how this can be implemented.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Alekseev, 2014-07-07
@bondarenko

Write a rake task and add it to cron (you can use the library https://github.com/javan/whenever)

T
Tonkonozhenko, 2014-07-14
@Tonkonozhenko

Use the sidekiq gem ( https://github.com/mperham/sidekiq)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question