> I think you're looking for Hash#to_query:
>
> h = { :a => 'b', :c => 'd' }
> opts = h.to_query # => "a=b&c=d"
>
Jeff, thanks, but no cigar.
But you got me real close and you got me to a solution.
Here's my solution which is, basically, a rip off of
activesupport-2.3.5\lib\active_support\core_ext\array\conversions.rb
activesupport-2.3.5\lib\active_support\core_ext\hash\conversions.rb
activesupport-2.3.5\lib\active_support\core_ext\hobject\conversions.rb
- - - -
class Array
def to_html_parms(key)
prefix = "#{key}[]"
collect { |value| value.to_html_parms(prefix) }.join ' '
end
end
class Hash
def to_html_parms(namespace = nil)
collect do |key, value|
value.to_html_parms(namespace ? "#{namespace}[#{key}]" : key)
end.sort * ' '
end
end
class Object
def to_html_parms(key)
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
"#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}"
end
end
- - - -
x={:ralph => 'marti', :steve => 'heller'}
x.to_html_parms # => "ralph=marti steve=heller"
- - - -
Now ... could someone explain to me what the cgi stuff does??
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.