Default rendered error file and hash to nice string how to

1 view
Skip to first unread message

Fernando Perez

unread,
Jul 26, 2010, 7:09:55 PM7/26/10
to rubyonra...@googlegroups.com
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
--
Posted via http://www.ruby-forum.com/.

Dave Aronson

unread,
Jul 27, 2010, 11:41:27 AM7/27/10
to rubyonra...@googlegroups.com
On Mon, Jul 26, 2010 at 19:09, Fernando Perez <li...@ruby-forum.com> 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

Marnen Laibow-Koser

unread,
Jul 27, 2010, 1:50:37 PM7/27/10
to rubyonra...@googlegroups.com
Fernando Perez 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
mar...@marnen.org

Fernando Perez

unread,
Jul 27, 2010, 4:46:14 PM7/27/10
to rubyonra...@googlegroups.com
> Are you looking for something like p or inspect ?

Damn' it! I completely forgot about Hash#inspect! Thanks Marnen :)

Fernando Perez

unread,
Aug 15, 2010, 12:16:20 PM8/15/10
to rubyonra...@googlegroups.com
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...

Marnen Laibow-Koser

unread,
Aug 16, 2010, 12:01:02 PM8/16/10
to rubyonra...@googlegroups.com
Fernando Perez 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
mar...@marnen.org

Reply all
Reply to author
Forward
0 new messages