What''s the fastest, easiest way to do URL encoding and decoding? (i.e., going from "Foo%20bar%24" to "Foo bar$" and vice versa) I couldn''t find any built-in functions to do this, which kind of suprised me. If I have to write it myself, how do I efficiently convert from a character to a hex representation? And what''s the best way to log error conditions in Rails? I don''t want my users to ever see an error. If one happens, I just want that part of the site to disappear from view. But that, of course, prevents me from knowing what happened unless I have logs. -- Bob Aman
On Apr 4, 2005 7:28 PM, Bob Aman <vacindak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What''s the fastest, easiest way to do URL encoding and decoding? > (i.e., going from "Foo%20bar%24" to "Foo bar$" and vice versa) > I couldn''t find any built-in functions to do this, which kind of suprised me. > If I have to write it myself, how do I efficiently convert from a > character to a hex representation?I''m not sure about that. I think it''s automatic? If this were perl, I''d use the ''pack'' function to convert between ASCII strings and hex-encoded URL strings, but I''m not aware of any ruby equivalent (being a ruby newbie).> And what''s the best way to log error conditions in Rails? I don''t > want my users to ever see an error. If one happens, I just want that > part of the site to disappear from view. But that, of course, > prevents me from knowing what happened unless I have logs.Set your environment to "production". Then if there''s an error, rails will simply display your public/500.html file (also public/404.html), which you can change to say whatever you want. Then you''ll have the log in log/production.log -- Urban Artography http://artography.ath.cx
On Apr 4, 2005, at 6:28 PM, Bob Aman wrote:> What''s the fastest, easiest way to do URL encoding and decoding? > (i.e., going from "Foo%20bar%24" to "Foo bar$" and vice versa)I think you might be looking for http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html require ''cgi'' CGI::escape("Foo bar$") CGI::unescape("Foo%20bar%24") Zach
> I think you might be looking for > http://www.ruby-doc.org/stdlib/libdoc/cgi/rdoc/index.html > > require ''cgi'' > CGI::escape("Foo bar$") > CGI::unescape("Foo%20bar%24")Yup, that''s what I was looking for. Was also looking for the logger object, but I found that, so I''m all good. -- Bob Aman