Update a record in a table in rails -


i have table a(:name, :flag) , want update flag column of record in table if condition evaluates true.

if a.find(300).flag == false  //will work -> a.find(300).flag = true 

what should write in line?

if a.find(300).flag == false  //will work -> a.find(300).flag = true 

change to

a.find(300).update(flag: true) if a.find(300).flag == false 

you can add method a.rb

def self.update_if_false id   find(id).update(flasg: true) if a.find(id).flag == false end 

then can use a.update_if_false(300)


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -