在Ruby on Rails书中看到这段代码.第一个是视图,第二个是辅助模块.我不明白怎么&block和attributes={}东西的工作.任何人都可以指导我一个解释这个的教程吗?
<% hidden_div_if(@cart.items.empty?, :id => "cart") do %>
<%= render(:partial => "cart", :object => @cart) %>
<% end %>
module StoreHelper
def hidden_div_if(condition, attributes = {}, &block)
if condition
attributes["style"] = "display: none"
end
content_tag("div", attributes, &block)
end
end
Run Code Online (Sandbox Code Playgroud)