Вопрос

It seems like the Rails console limits its character output to about 880 characters. How do I remove this limitation?

Printing large objects, or text fields from the database, gives output like this:

=> #<User id: ....
system_password: ni

(... inserted for brevity. The output contains lots and lots of text.)

You can see that the output is truncated / capped/ limited, so that nothing after 'ni' is displayed (should have been atleast an 'l', for 'nil').

This is so annoying. It doesn't allow me to fully inspect the string / text fields in the DB that contain a lot of text.

I presume it must be a setting somewhere, but I can't seem find it.

How do I remove this limitation, so I can see all of the text output?

Это было полезно?

Решение

I don't think irb or the Rails console is the problem. This doesn't truncate from either plain irb or rails c:

(1..100000).reduce(''){|a,i| a << i.to_s}

The Rails console output is coming from the inspect method, so it's probably ActiveRecord that is doing the truncation (code here). You should be able to override the inspect method in your User model if you want custom output.

Другие советы

I would like to recommend pry, which supports Rails well and you can view details of ActiveRecord instances with it.

I had the same issue and got past it by requesting just the one field I needed. For example, saying Vote.find(38) yielded text with a ..., but when I went straight to Vote.find(38).description it had the unshortened version.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top