undefined method `update_attributes' in ruby on rails -


this update process different need update query inside loop, showing error:

undefined method `update_attributes'

this code:

<%= link_to "accept", apply_path(accept:{:accept => 1}), :method => :put, class: "btn btn-success" %>    

controller:

def update   @accept = applied.where(params[:applied_id])   params.permit!   if @accept.update_attributes(params[:applied_id])     #flash[:notice] = "updated"     render 'apply'   else     render 'apply'   end end 

request parameters:

{"_method"=>"put", "authenticity_token"=>"yk26lkrw9ulrvv6p8gwhqtp7cosg96jiamu4cuyyfugbgtdr2irzzlyy1sq7tba7b2yvmgulgcwtosxvjnpxzw==", "accept"=>{"accept"=>"1"}}

how can reach solution?

you can call update_attributes single model instance (a record) not activerecord::relation object (it's array of records).

use:

@accept = applied.where({applied_id:params[:applied_id]}).first 

or

@accept = applied.find(params[:applied_id]) 

be aware, find looks applied_id in id field of model table, if haven't config in place.

and note update_attributes consumes hash of "field:value" pairs ({field_1_name:field_1_value, field_2_name:field_2_value}) want update, not single applied_id only.


Comments