I am using the Pry gem in my Rails console, but the pry flavored rails-console seems to have lost the reload! method for reloading models and stuff.
Here's how I start the pry console
c:\rails\app> pry -r ./config/environment
Thank You
Installation. To get started using Pry, simply include the gem 'pry-rails' and 'pry-doc' in your Gemfile, and bundle install! Now every time you boot your rails console you'll have a Pry shell.
We've added pry-doc to access the Ruby core documentation. To start pry, simply type pry after the gem is installed. You can also make it part of your application's dependencies by adding gem "pry" to your application's Gemfile. Installing pry from within the application has its own benefits.
Pry is a runtime developer console and IRB alternative with powerful introspection capabilities. Pry aims to be more than an IRB replacement. It is an attempt to bring REPL driven programming to the Ruby language.
To use reload! like the rails console command, add this code to your .pryrc
# load Rails Console helpers like reload require 'rails/console/app' extend Rails::ConsoleMethods puts 'Rails Console Helpers loaded'
EDIT== Gem pry-rails already do all of this, much simplier .
For anyone coming to this question recently: the answer has changed in Rails 3.2, because they've changed how they implement reload!
Where in earlier version the irb commands were added as methods to Object
, now they are added to IRB::ExtendCommandBundle
to avoid polluting the global namespace.
What I do now is (1) in development.rb
silence_warnings do begin require 'pry' IRB = Pry module Pry::RailsCommands ;end IRB::ExtendCommandBundle = Pry::RailsCommands rescue LoadError end end
and (2) in .pryrc
if Kernel.const_defined?("Rails") then require File.join(Rails.root,"config","environment") require 'rails/console/app' require 'rails/console/helpers' Pry::RailsCommands.instance_methods.each do |name| Pry::Commands.command name.to_s do Class.new.extend(Pry::RailsCommands).send(name) end end end
Here's the link to the Rails pull request where the change was introduced - https://github.com/rails/rails/pull/3509
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With