# Taking key/value pairs and formating into string

**URL:** <https://www.ruby-forum.com/t/taking-key-value-pairs-and-formating-into-string/121593>\
**Category:** Rails\
**Created:** [November 29, 2007, 4:02am UTC](https://www.ruby-forum.com/t/taking-key-value-pairs-and-formating-into-string/121593 "2007-11-29T04:02:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mifi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@mifi](https://www.ruby-forum.com/u/mifi)\
**Post date:** [November 29, 2007, 4:02am UTC](https://www.ruby-forum.com/t/taking-key-value-pairs-and-formating-into-string/121593/1 "2007-11-29T04:02:32Z")

</div>

Hi all,

I am really new to Ruby so I haven’t figured out all of the iterative  
functions yet, but here is my situation and I appreciate your input.

I am trying to utilize a custom method inside my application helper that  
will tie into tabbed forms. The concept is to change various DOM  
elements on page load so that their visibility is hidden when the page  
is loaded (e.g. new.rhtml) and then when the appropriate tab is click a  
link\_to\_function call will change their visibility. I am attempting to  
set the hash values inside the partial then return them using “yield”  
inside the tag.

So, here is what I have so far:

application.rhtml (default layout)

\>

application\_helper.rb

def onload\_content( options = {} )  
content\_for :onload\_content do  
if options.blank?  
nil  
else  
options.each\_pair do |key, value|  
“$(’#{key}’).#{value}();”  
end  
end

I am taking advantage of the Prototype library such that i can call:  
$(element).hide() or $(element).show()

so…

I make a call to the onload\_content method from inside the partial  
containing the DOM elements I wish to hide onload:

\_form.rhtml  
\<% onload\_content :contacts =\> :hide, :notes =\> :hide, :demographics =\>  
:show %\>

…remainder of form …

however, when I attempt to set the options I receive TypeError exception  
returning : “(eval):1:in `+’: can’t convert Hash into String”

I know this is a syntax mistake I am making, but I’ve been looking over  
my copy of Pickaxe and browsing the Net without much help. If you  
guys/gals could point me in the right direction, I would really  
appreciate it.

- Mike

P.S. if any of you have come across a better solution I would love the  
ideas!!
