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

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -