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

reload! - undefined method #9

Closed
scottwater opened this issue Jan 26, 2012 · 17 comments
Closed

reload! - undefined method #9

scottwater opened this issue Jan 26, 2012 · 17 comments

Comments

@scottwater
Copy link
Contributor

Using pry-rails (0.1.2) causes reload! to no longer work in Rails 3.2. with Ruby 1.9.3.

If I remove the pry-rails gem and use irb, it works as expected.

Exact Message:

Loading development environment (Rails 3.2.0)
[1] pry(main)> reload!
NoMethodError: undefined method `reload!' for main:Object

Thanks,
Scott

P.S. I also noticed the app variable is no longer available.

@eagsalazar
Copy link

same problem. please document a workaround or add these helpers. Thanks.

@scottwater
Copy link
Contributor Author

A short term fix is to do this in the console:

self.send(:include, Rails::ConsoleMethods)

I have a pull request coming which does this as well....although it feels a little dirty.

@Tomtomgo
Copy link

Tomtomgo commented Feb 7, 2012

Is there a way to add this to the 'rails c' startup sequence? Now I'ḿ copy-pasting this everytime...

@scottwater
Copy link
Contributor Author

@Tomtomgo - Grab the latest version of the gem. The fix has been merged in.

@Tomtomgo
Copy link

Nice one.

@joshco
Copy link

joshco commented Aug 2, 2012

I'm still seeing a problem : (Win7 mingw, pry 0.9.10)
pry is the only gem installed (no pry-*)
Im running pry -r ./config/environment

[4] pry(main)> reload
NameError: undefined local variable or method reload' for main:Object from (pry):4:inpry'
[5] pry(main)> reload!
NoMethodError: undefined method reload!' for main:Object from (pry):5:inpry'
[6] pry(main)> self.send(:include, Rails::ConsoleMethods)
NameError: uninitialized constant Rails::ConsoleMethods
from (pry):6:in `pry'
[7] pry(main)>

@volkanunsal
Copy link

Same problem here....

@lishuaiii
Copy link

Same problem

@jessicard
Copy link

Same problem on Rails 3.2, Ruby 2.1.1 :(

@rf-
Copy link
Member

rf- commented Jul 23, 2014

In addition to the possibility that this is a bug, there are a couple of non-bug reasons this could be happening to you.

First of all, the helpers are only available if you run rails console, not if you use binding.pry within your app. This is following the lead of Rails, which only loads those methods in the console context and not when you run rails server or specs or whatever.

Another potential reason they might not be there is if you've cded or binding.pryed into a context other than the top level. Before Rails 3.2, the app, helper, and reload! methods got mixed into Object, so they would be available regardless of what context you're running code in. Since Rails 3.2, they've been mixed into the top-level context (main) instead, so they're only available in the context that the console initially starts in. We could change that, but it would be different from the stock behavior of Rails.

BTW, I feel like either of those decisions could be revisited if people want the extra convenience in exchange for monkey-patching Object more aggressively. I don't think anyone has ever explicitly asked for those changes, but they would probably reduce confusion, so maybe we should talk about it.

If anyone in this thread is seeing this problem and the reasons above don't apply, please leave some extra details about what you're doing so that we can try to track down what's going on.

@lime
Copy link

lime commented Jul 24, 2014

Thanks @rf-, that clarifies a lot of things! I was pretty confused when rails console gave me the helpers while zeus console and binding.pry did not.

Also, I think the initiative to consider changing this behaviour is great. Maybe it should have its own issue however, so as not to hijack this discussion?

@baweaver
Copy link

I'd consider that for another issue. If you're in a Rails app, chances are high that you probably want to have everything loaded in as well.

@umuro
Copy link

umuro commented Jan 31, 2015

Reload workaround is as follows:

~/.pryrc

if defined?(Rails) && Rails.env
  if defined?(Rails::ConsoleMethods)
    include Rails::ConsoleMethods
  else
    def reload!(print=true)
      puts "Reloading..." if print
      ActionDispatch::Reloader.cleanup!
      ActionDispatch::Reloader.prepare!
      true
    end
  end
end

@g8d3
Copy link

g8d3 commented Sep 29, 2015

thanks @umuro .

@jaredatron
Copy link

# .pryrc checked into my project root
require 'rails/console/app'
include Rails::ConsoleMethods

@counterbeing
Copy link

that did the trick @deadlyicon 👍

@jaredatron
Copy link

cheer

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