task.rb
class Task < ApplicationRecord
validates :name, presence: true
validates :due_date, presence: true
validates :company_name, presence: true, default: “Next Level Events”
validates :status, presence: true, inclusion: { in: %w(pending completed) }
validates :assigned_date, presence: true
validates :target_date, presence: true
belongs_to :event
after_create :create_reminder
after_update :update_reminder
private
def create_reminder
ReminderJob.set(wait_until: self.due_date).perform_later(self)
end
def update_reminder
ReminderJob.set(wait_until: self.due_date).perform_later(self)
end
end
tasks_controller.rb
class TasksController < ApplicationController
def new
@task = Task.new
@task.
Here is the code fixed up, you will need to setup authorization
class Task < ApplicationRecord
validates :name, presence: true
validates :due_date, presence: true
validates :company_name, presence: true, default: “Next Level Events”
validates :status, presence: true, inclusion: { in: %w(pending completed) }
validates :assigned_date, presence: true
validates :target_date, presence: true
belongs_to :event
after_create :create_reminder
after_update :update_reminder
private
def create_reminder
ReminderJob.set(wait_until: self.due_date).perform_later(self)
end
def update_reminder
ReminderJob.set(wait_until: self.due_date).perform_later(self)
end
end
class TasksController < ApplicationController
def new
@task = Task.new
end
def create
@task = Task.new(task_params)
if @task.save
redirect_to @task
else
flash.now.alert = @task.errors.full_messages.to_sentence
render :new
end
end
def edit
@task = Task.find(params[:id])
end
def update
if @task.update(task_params)
redirect_to @task
else
flash.now.alert = @task.errors.full_messages.to_sentence
render :edit
end
end
private
def task_params
params.require(:task).permit(
:name,
:due_date,
:company_name,
:status,
:assigned_date,
:target_date
)
end
end
(you can scroll to see the rest)