Is it possible to view/browse Rails documentation with pry? How?
(pry-rails appears to be for project source, and pry-doc covers Core Ruby.)
Is ri the preferred local doc browsing tool for Rails?
Thanks!
Pry will only show you documentation for dependencies that you have explicitly loaded. The easiest way to get all the Rails dependencies is to run pry in a Rails project's directory like so:
pry -r ./config/environment
Now you're ready to see Rails' internal documentation through pry. However, as you noted Rails' documentation is written with ri in mind. So instead of using show-doc
if you run ri ActiveRecord::Base
you should see:
ActiveRecord::Base < Object
------------------------------------------------------------------------------
Includes:
(from gem activerecord-4.1.1)
Core
Persistence
NoTouching
ReadonlyAttributes
ModelSchema
Inheritance
Scoping
Sanitization
AttributeAssignment
ActiveModel::Conversion
Integration
Validations
.... it eventually gets to the actual documentation but you get the idea ...
(I believe show-doc
does not work for ActiveRecord::Base
because there's a #:nodoc:
directive in that file's source code. Perhaps someone can chime in in the comments or add an edit.)
Alternatively, you can load each dependency you want manually. If you opened up a normal pry session and run require 'active_record'
the same ri
command will work.
This should work with the rails console as well if you use the pry-rails gem or a custom initializer to set pry as the default REPL.