Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pry-rails doesn't pretty print devise models #83

Open
rycwilson opened this issue Sep 2, 2016 · 9 comments
Open

pry-rails doesn't pretty print devise models #83

rycwilson opened this issue Sep 2, 2016 · 9 comments

Comments

@rycwilson
Copy link

After using these two gems together successfully for the last year, suddenly the console won't pretty print either of my devise models. All other models print in the console as expected, but User and Admin print in the traditional rails/irb fashion.

Curiously this manifests in a dev branch but not in my master branch, so I suppose that gives me hope for tracking down the problem. Gemfiles are identical - both contain pry-rails 0.3.4 and pry 0.10.4. Precisely nothing was changed in user.rb or admin.rb prior to this problem appearing.

Any tips for debugging?

@rycwilson
Copy link
Author

Problem seems to be restricted to Active Record methods: User.all, User.first, User.where(...), etc

show-model User output prints as expected

@fsladkey
Copy link

I'm also experiencing this issue and I'm not sure where to start looking for a solution. Did you happen to find a fix?

@rycwilson
Copy link
Author

No solution, instead I switched to Jazz Hands:
https://github.com/nixme/jazz_hands

Works great with a few caveats:

1 - I have noticed some issues with binding.pry (e.g. if I mistype a
command when I'm in a bound pry shell, it goes into a weird state where
everything I type comes up with random key mappings and I can't exit the
shell, have to re-start the server).

2 - Also have seen line-wrapping issues when I'm using iTerm2 with multiple
shells open

This is my setup:

gem 'jazz_hands', github: 'nixme/jazz_hands', branch:
'bring-your-own-debugger'
gem 'pry-byebug'

On Tue, Oct 25, 2016 at 1:34 PM, Fred Sladkey [email protected]
wrote:

I'm also experiencing this issue and I'm not sure where to start looking
for a solution. Did you happen to find a fix?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#83 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AJwvpPuiX82fUEUsXE-uSu1ZocxUN_xtks5q3mfDgaJpZM4JzRc9
.

@fsladkey
Copy link

Okay, thanks! Nice to have an alternative. I realized my issue may have something to do with using rails 5 but haven't tried to replicate it in earlier versions. If I find a solution or explanation I'll post here.

@rycwilson
Copy link
Author

As luck would have it jazz_hands appears to be incompatible with Rails 5, as it requires Railties < 5, while Rails 5 requires Railties = 5.

Doesn't seem as though either pry-rails or jazz_hands are maintained any longer. Are there alternatives out there??

@rycwilson
Copy link
Author

Try this for a fix:

gem 'pry-rails'
gem 'awesome_print'

... and in your .pryrc, add this (ref):

begin
  require 'awesome_print'
  AwesomePrint.defaults = {
    indent: -2, # left aligned
    sort_keys: true, # sort hash keys
    # more customization
  }
  Pry.config.print = proc { |output, value| Pry::Helpers::BaseHelpers.stagger_output("=> #{value.ai}", output) }
rescue LoadError => err
  puts "no awesome_print :("
end

@marcelkooi
Copy link

+1 User no longer pretty prints. Using devise as well.

@tomdracz
Copy link

Caused by Devise authenticable module having custom inspect method:

https://github.com/plataformatec/devise/blob/a0232cf76338927433f76e103fdfe8b66f93fe8a/lib/devise/models/authenticatable.rb#L119-L124

PP then tries its best to do something, but hasn't got line breaks or anything, as per https://github.com/ruby/ruby/blob/trunk/lib/pp.rb#L295-L321

Solution is to either use awesome_print as formatter OR define custom pretty_print method, check the docs here http://ruby-doc.org/stdlib-2.0.0/libdoc/pp/rdoc/PP.html

@srichsun
Copy link

srichsun commented Mar 6, 2018

@rycwilson it works perfectly !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants