# How does this helper work? (agile book)

**URL:** <https://www.ruby-forum.com/t/how-does-this-helper-work-agile-book/89941>\
**Category:** Rails\
**Created:** [March 24, 2007, 12:38am UTC](https://www.ruby-forum.com/t/how-does-this-helper-work-agile-book/89941 "2007-03-24T00:38:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![desertfox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@desertfox](https://www.ruby-forum.com/u/desertfox)\
**Post date:** [March 24, 2007, 12:38am UTC](https://www.ruby-forum.com/t/how-does-this-helper-work-agile-book/89941/1 "2007-03-24T00:38:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![desertfox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@desertfox](https://www.ruby-forum.com/u/desertfox)\
**Post date:** [March 24, 2007, 1:15am UTC](https://www.ruby-forum.com/t/how-does-this-helper-work-agile-book/89941/2 "2007-03-24T01:15:05Z")

</div>

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:

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
