I have written a rest api in ruby on rails that saves timesheets to a database. Before saving the timesheet, I am trying to set the timesheet's time property to the current time, Time.now. However, the time always gets set to null.
Here is my create method:
def create
@timesheet = Timesheet.new
@timesheet.assign_attributes(@json['timesheet'])
@timesheet.time = Time.now
if @timesheet.save
render json: @timesheet
else
render nothing: true, status: :bad_request
end
end
I am testing via terminal and I always get json back with time:null. Thanks for any help.
edit: Schema
create_table "timesheets", force: :cascade do |t|
t.integer "employer_id"
t.integer "employee_id"
t.datetime "time"
t.boolean "in"
end