Thursday, 5 September 2013

ROR update params in controller

ROR update params in controller

I have a controller in which i want to update the value of one of the
parameters before the update so the update is carried in the same save to
the database. unfortuently the following code does not set z in the
database.
if @model.x == "YES" && @model.z.blank?
model_params[:z] = Time.now
end
@model.update_attributes(model_params)
def model_params
params.require(:model).permit(:x, :y, :z)
end

No comments:

Post a Comment