ctw
Joined
Activity
thsi episode is too easy!
I have use Vue.js and user *vue, the single file component.
so, how to deploy it?
Anyone know?
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