3

For a blog model I'm saving an RSS field as text under Blog.rss, problem is, some of this is rather long and each one prints when I'm working in the rails console, ie: Blog.last(10).

Is there a way to hide output unless I call someblog.rss specifically?

Ashbury
  • 2,160
  • 3
  • 27
  • 52
  • Use hirb: https://github.com/cldwalker/hirb – Linus Oleander Feb 06 '16 at 06:33
  • I don't know if there is a way to Limit a text output but i suggest trying out https://github.com/michaeldv/awesome_print. It let's you have Formatted outputs + has limit option for Arrays/Hashes. – midN Feb 06 '16 at 07:18
  • maybe this one [how-to-suppress-rails-console-irb-outputs](http://stackoverflow.com/questions/4678732/how-to-suppress-rails-console-irb-outputs) – sugaryourcoffee Feb 06 '16 at 10:18

2 Answers2

0

I had a similar problem and received some solutions in another forum, which were:

  • Use select to get just the columns you need
  • If you have a very long column (I had JSON data structure from a webhook cluttering the console), consider whether you really need it, and if you don't , don't store it in the table
    • Or, consider storing it in an associated table
  • if you need the whole object but just want to change how it's represented in console/log output, you can redefine inspect
  • yourobject.as_json(except: :unwanted_column)

Also

stevec
  • 41,291
  • 27
  • 223
  • 311
0

You can override the #inspect method in your Blog model. This code would truncate the string it prints when referencing an object in console.

  def inspect
    inspection = super
    inspection[0..300] + ((inspection.length > 300) ? "..." : "")
  end
ScotterC
  • 1,054
  • 1
  • 10
  • 23