<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: hash code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 07:24:41 GMT</pubDate>
    <description>DZone Snippets: hash code</description>
    <item>
      <title>PrototypeHelper :with helper</title>
      <link>http://snippets.dzone.com/posts/show/2216</link>
      <description>This method is for use in conjuction with the Ruby on Rails Module &lt;a href="http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper.html"&gt;ActionView::Helpers::PrototypeHelper&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The options hash takes any number of key/value pairs the key becomes the name of the parameter passed in the with value and the value becomes a javascript expression&lt;br /&gt;&lt;br /&gt;key &#8212; name of the parameter&lt;br /&gt;value &#8212; a fragment of javascript that will be the value of the parameter&lt;br /&gt;&lt;br /&gt;Example&lt;br /&gt;&lt;pre&gt;&gt;&gt; params_for_with(:clean_range =&gt; 'clean_range', :raw_range =&gt; 'raw_range', :total_count =&gt; 'total_count')&lt;br /&gt;=&gt; 'total_count=' + total_count + '&amp;' + 'clean_range=' + clean_range + '&amp;' + 'raw_range=' + raw_range&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Don&#8216;t forget you won&#8217;t necessarily get the parameters out in the same order you put them in, such is the nature of hashes&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def params_for_with(options = {})&lt;br /&gt;    options.collect { |param_name, js_fragment| "'#{param_name}='+#{js_fragment}" }.join("+'&amp;'+")&lt;br /&gt;    # or this one&lt;br /&gt;    #options.stringify_keys.collect { |param_name, js_fragment| '"' &lt;&lt; param_name &lt;&lt; '="+' &lt;&lt; js_fragment }.join('+"&amp;"+')&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 18 Jun 2006 20:52:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2216</guid>
      <author>sporkyy (Todd Sayre)</author>
    </item>
  </channel>
</rss>
