ctw

Joined

2,150 Experience
21 Lessons Completed
0 Questions Solved

Activity

Posted in Link To Current Page With Params Discussion

thsi episode is too easy!

Posted in Deploy Ubuntu 16.04 Xenial Xerus Discussion

I have use Vue.js and user *vue, the single file component.
so, how to deploy it?
Anyone know?

Posted in Group Chat with ActionCable: Part 4 Discussion

I've figure out the problem. a trick.
after use form_with, you must change the code in this video.
my code in chatrooms.coffee:
document.addEventListener 'turbolinks:load', ->
document.getElementById("new_message").addEventListener 'keypress', (e) ->
if e && e.keyCode == 13
e.preventDefault()
url = this.action
data = new FormData(this)
Rails.ajax({
type: "POST"
url: url
data: data
dataType: "json"
})

must use save! or update!

def withdraw(amount)
update!(balance: balance - amount)
end

def deposit(amount)
update!(balance: balance + amount)
end

sally.transfer(bob, 10000), it is not rollback!

why?

class Account < ApplicationRecord
validates :balance, numericality:{ greater_than: 0}

def withdraw(amount)
update(balance: balance - amount)
end

def deposit(amount)
update(balance: balance + amount)
end

def transfer(recipient, amount)
transaction do
withdraw(amount)
recipient.deposit(amount)
end
end
end