rails class reminders code example

Example 1: rails class sti reminders

class AddNotes < ActiveRecord::Migration[5.2]
  def change
    create_table :notes do |t|
      t.string :type # this tells Rails we plan on using STI
      t.string :title
      t.boolean :is_completed
      t.jsonb :data, default: {}
      t.timestamps
    end

    add_index :notes, :data, using: :gin
  end
end

Example 2: rails class note reminders

ReminderJob = Struct.new(:event) do def enqueue(job)   job.delayable = event   job.save! end def perform   event.send_reminder end def queue_name   'reminder_queue' endend

Example 3: rails class note reminders

after_save :new_reminder def new_reminder   Delayed::Job.enqueue(ReminderJob.new(self), { run_at: self.when_to_run }) end def send_reminder   # Send a text message reminder 2 hours before event start   @client = Twilio::REST::Client.new(Rails.application.credentials.twilio_account_sid, Rails.application.credentials.twilio_auth_token)   @client.messages.create({     from: "Name",     to: "phone number",     body: "Message to the user"     }) end def when_to_run   minutes_before_appointment = 120.minutes   self.starts_at - minutes_before_appointment end

Tags:

Ruby Example