Ruby on rails : using update inside show for REST API -


while accessing rest api on rails encountered inside rails console can happen

variable = model.find(1) //random id variable.update(:column => variable.column + 1) //my column numeric 

but this, while possible on console cannot find translation ruby api exact method

any ideas?

seems you're trying increment counter whenever access show method in controller. can achieved increment! method activerecord::persistence class:

instance = model.find(params[:id]) instance.increment!(:attribute_to_increment, = 1) 

note :attribute_to_increment has numeric.

source: https://apidock.com/rails/v4.2.7/activerecord/persistence/increment%21


Comments

Popular posts from this blog

php - Embed BBCode within itself not working -

three.js - how to load gltf in three JS -

sql server - T-SQL: Access DB objects in same schema without qualifying? -