Updating params before saving to database

I have an exercise app that will take the number of reps done and subtract it from the amount that are “owed” for the day, I save those in a single row that is sent to the user where it is displayed, and they put the amount done.

In the create controller, I then take the amount “paid” and subtract it from the amount “owed” and try to update the params…but the params don’t update.

From what I can read there is something to do with the strong params being a different hash and I need to update that, but I can’t for the life of me figure out how to do that. Any advice on where to look or what to log to see it would be greatly appreciated!

So I solved the problem I think, but is this really the best way to do it?

def create
owed_total = burpee_params[:owed_total].to_i
owed_today = burpee_params[:owed_today].to_i
paid = burpee_params[:amount_paid].to_i
new_owed_total = (owed_total - paid).to_s
new_owed_today = (owed_today - paid).to_s

new_burpee_params = burpee_params
new_burpee_params[:owed_total] = new_owed_total
new_burpee_params[:owed_today] = new_owed_today

@burpee = Burpee.new(new_burpee_params)

if @burpee.save
    redirect_to @burpee, notice: 'You paid some burpees!'

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs