Default rendered error file and hash to nice string how to

Hi,

When rails raises an exception which file (view?) gets rendered and
outputs in the browser the backtrace, request, parameters, etc.

I’m asking that because I’d like to know if Rails provides an easy way
to convert a hash to a readable string, eg:

“{:key => ‘value’}” instead of yukky #to_s which gives “keyvalue”.

Thanks

On Mon, Jul 26, 2010 at 19:09, Fernando P. [email protected]
wrote:

I’d like to know if Rails provides an easy way
to convert a hash to a readable string, eg:

“{:key => ‘value’}” instead of yukky #to_s which gives “keyvalue”.

Maybe you can override to_s?

-Dave


Specialization is for insects. -RAH | Have Pun, Will Babble! -me
Programming Blog: http://codosaur.us | Work: http://davearonson.com
Leadership Blog: http://dare2xl.com | Play: http://davearonson.net

Fernando P. wrote:

Hi,

When rails raises an exception which file (view?) gets rendered and
outputs in the browser the backtrace, request, parameters, etc.

I’m asking that because I’d like to know if Rails provides an easy way
to convert a hash to a readable string, eg:

“{:key => ‘value’}” instead of yukky #to_s which gives “keyvalue”.

Are you looking for something like p or inspect ?

Thanks

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

I think I’m experiencing an issue with Hash#inspect: if one of the
values holds a file, it seems Ruby keeps it as a file, so I’ll let you
guess what may happen if the file is a bit big when I just expect a
little string to represent that file…

Are you looking for something like p or inspect ?

Damn’ it! I completely forgot about Hash#inspect! Thanks Marnen :slight_smile:

Fernando P. wrote:

I think I’m experiencing an issue with Hash#inspect: if one of the
values holds a file, it seems Ruby keeps it as a file, so I’ll let you
guess what may happen if the file is a bit big when I just expect a
little string to represent that file…

So check for File values. What’s the problem?

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]