Hello,
Im trying to understand how this helper method works:
def hidden_div_if(condition, attributes = {})
if condition
attributes["style"] = "display: none"
end
attrs = tag_options(attributes.stringify_keys)
"<div #{attrs}>"
end
This is how they are calling it:
<%= hidden_div_if(@cart.items.empty?, :id => "cart") %>
Specifically, I need to know if the :id => "cart" is passed on to
attrs
with the style attribute...
And also, what does the tag_options(attributes.stringify_keys) do?
Thanks in advance!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Basically, tag_options() will create a set of html tag attributes from
a hash:
tag_options({"id" => "cart", "style" =>
"color: black"})
will give you:
id="cart" style="color: black"
which is convenient to use in a tag:
<div id="cart" style="color: black">
stringify_keys is a method for hashes that converts any symbol keys to
strings. For example {:id => "cart"} becomes {"id" =>
"cart"}
Hope that helps,
Steve
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Apparently Analagous Threads
- From the Agile book, page 144 regarding a div tag helper
- question about method "hidden_div_if" in AWDR 2
- need help trying to debug - included screenshot
- The Depot "Add to Cart" sessions question (2.ed agile book)
- new to rails; problem with testing section in Agile book