Rails Model SQL Data Operations

create, update, delete

update_all

Update all which are matched condition
Example1

def update_all
  Item.where(category: 'new').update_all(category: 'old')
end

Example2

def update_limit
  @cnt = Item.order(:date).limit(5).update_all('price = price * 0.7')
end

destroy, delete

destroy : select -> delete
delete : delete

def destroy
  Item.destroy(params[:id])
end

destroy_all

def destroy_all
  Item.destroy_all(['price > ?', 45])
end