0
我正在讀這本書敏捷web開發與rails 4. 有一部分產品的購物車只顯示它不是空的,我的問題是在查看發送給助手只有2個屬性,而在實現中有3個參數。方法屬性[ajax,jquery,rails4]
視圖我有婁代碼,使細胞對_cart在那裏我有車顯示
<%= hidden_div_if(@cart.line_items.empty?, id: 'cart') do %>
<%= render @cart %>
<% end %>
的助手有:
module ApplicationHelper
def hidden_div_if(condition, attributes = {}, &block)
if condition
attributes["style"] = "display: none"
end
content_tag("div", attributes, &block) end
end
我的問題是,在這種情況下,&塊收到id:'cart',但它是一個可選attibute?那爲什麼它與&。但是屬性= {}呢? 我真的不知道這是怎麼回事,有人能解釋我一點嗎?
謝謝!
偉大的我去吧,我會嘗試做一些測試,讓你知道! – Moh