How to use update_attributes in rails 4?

I am currently updating my application from rails 3.2 to rails 4. The following error has appeared.

ArgumentError (argument out of range): 

This error occurred due to the following line of code

 @lease.update_attributes(params[:lease]) 

I tried an update that also threw the same error. Is update_attributes from rails fixed. 4. How to use it?

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 
+6
source share
2 answers

Just use @lease.update(lease_params) this, and also add a private method in the controller

 def lease_params params.require(:lease).permit! end 
+8
source

In Rails 4, we can expect update_attribute () to be renamed. The name of the new method is called update_column (). See This commit for more information.

https://github.com/rails/rails/commit/a7f4b0a1231bf3c65db2ad4066da78c3da5ffb01

-2
source

Source: https://habr.com/ru/post/958848/


All Articles