Currently I am upgrading my application from rails 3.2 to rails 4. Got the following error.
ArgumentError (argument out of range):
This error occured because of following line of code
@lease.update_attributes(params[:lease])
I tried by update that also throw the same error. Is update_attributes removed from rails 4.how to use this?
code:
def terms_build_methods
if @lease.blank?
@lease = params[:current_lease_id].present? ? Lease.find_by_id(params[:current_lease_id].to_i) : Lease.create(params[:lease])
else
@lease.update(lease_params)
end
Lease.update_lease_occupancy_type(@lease)
Lease.update_lease_status(@lease)
end
private
def lease_params
params.require(:lease).permit!
end
This method used to be called update_attributes in Rails 3. It changes the attributes of the model, checks the validations, and updates the record in the database if it validates. Note that just like update_attribute this method also saves other changed attributes to the database.
Use update_attribute to skip validations. update_attribute uses save(false) while update_attributes uses save (which means save(true)). If perform_validation is false while calling save then it skips validation, and it also means that all the before_* callbacks associated with save.
Use update_attribute to change an attribute and persist it without running validations. Use update to change an attribute, check the validations and persist the change if validations pass. You can find an object and update it with a one command using update as class method.
Just use @lease.update(lease_params)
this and also in the controller add a private method
def lease_params
params.require(:lease).permit!
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With