Object 今天學(xué)的記得什么?
購(gòu)物車明細(xì)里,商品數(shù)量可以更改,且不能超過庫(kù)存數(shù)量。
Step 1: app/views/carts/index.html.erb中,增加以下code
<%= form_for cart_item, url: cart_item_path(cart_item) do %>
<%= f.select :quantity, 1..cart_item.product.quantity %>
<%= f.submit "更新", data: {disable_with: "submitting..."} %>
<% end %>
Step 2: cart_items controller里,修改update method
def update
@cart_item = current_cart.cart_items.find(params[:id])
if @cart_item.product.quantity >= cart_item_params[:quantity]
@cart_item.update(cart_item_params)
flash[:notice] = "成功更新"
else
flash[:warning] = "商品數(shù)量不足以加入購(gòu)物車"
end
end
Reflection 今天情緒的高點(diǎn)和低點(diǎn)是什么?
高點(diǎn):中秋節(jié),這個(gè)讓人聯(lián)想起家人團(tuán)聚的日子。晚上,家人給我打來電話,聊了些家常,知道他們?cè)谝黄疬^節(jié),聽到他們聲音和笑聲,感覺到溫暖、開心。
低點(diǎn):臨近中午12點(diǎn),肚子餓了,精神難集中,易煩躁,感覺不太好。不適合在這種狀態(tài)下做耗神的活,比如學(xué)習(xí)新東西、打coding等。
Interpretation 今天一個(gè)重要的領(lǐng)悟是什么?
非嵌套的view里,針對(duì)object做form_for時(shí),無需專門指明url。因?yàn)閞outing、controller、view三者一致,可以直接找到。
嵌套的view里,針對(duì)object做form_for時(shí),則需專門指明url。比如文章開頭的例子:
<%= form_for cart_item, url: cart_item_path(cart_item) do %>
Decision 明天要做什么?
按照精進(jìn)練習(xí)的schedule, 做web API 設(shè)計(jì)實(shí)做。