Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Default function for Increment/Decrement updates database field values in rails 2.3.8

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 384
    Comment on it

    Generally at the time of development a situation of incrementing or decrementing a database field it can come like Number of views for a particular page or Number of views of a individual profile. In rails there are two default functions for this which can increment/decrement DB fields values. Below is the syntax and description of the function:

    ModelName.increment_counter(:views_count, 5)

    Here,

    ModelName is the name of the model class increment_counter(increment in rails 3) is the function which will increment the database field by 1 with id 5 and views_count is the name of the database field on which the operation will be perform. So if the value was 10 so after this it will update the value as 11. On the other hand there is also a function which do opposite of this the function is decrement_counter(decrement in rails 3).

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: