Debugger going to implicit.rb automatically - ruby-on-rails

I installed debugger gem in my gemset
<pre>
nikhil#nikhil-K54C:/media/media1/railscode/beasport$ bundle show debugger
/home/nikhil/.rvm/gems/ruby-1.9.3-p194#beasport/gems/debugger-1.2.0
</pre>
My intention is to use this gem to debug my application by placing "debugger" call in my code so that i can use it to debug application.
However strangely even if i have not put "debugger" call anywhere in my code but still whenever i hit any url to my application (from localhost:3000), debugger starts debugging in file
<pre>
/home/nikhil/.rvm/gems/ruby-1.9.3-p194#beasport/gems/actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb
</pre>
here is what i get when i do "list"
<pre>
=> Ctrl-C to shutdown server
[2012-11-07 19:11:18] INFO WEBrick 1.3.1
[2012-11-07 19:11:18] INFO ruby 1.9.3 (2012-04-20) [i686-linux]
[2012-11-07 19:11:18] INFO WEBrick::HTTPServer#start: pid=6602 port=3000
/home/nikhil/.rvm/gems/ruby-1.9.3-p194#beasport/gems/actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb:5
default_render unless response_body
(rdb:1) list
[0, 9] in /home/nikhil/.rvm/gems/ruby-1.9.3-p194#beasport/gems/actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb
1 module ActionController
2 module ImplicitRender
3 def send_action(method, *args)
4 ret = super
=> 5 default_render unless response_body
6 ret
7 end
8
9 def default_render(*args)
(rdb:1)
</pre>
I am using webrick. This is frustrating. When i remove debugger gem from gemfile and do "bundle install" then it works fine but i wont be able to debug my application then.
Again i checked with my other application and there debugger works just fine and do not go to implicit.rb unnecessarily.
Please help

I know this is a question posted last year
and you may no longer need answer, but since I also had the same issue and had to solve it myself, I'm posting what worked for me.
gem uninstall debugger
gem uninstall debugger-linecache
gem uninstall debugger-ruby_core_source
Then,
gem install debugger

Related

How to debug in rails server console?

I am new to ruby on rails, I want to debug my rails application through debugger i rails server console.So please tell me shortcuts and there meaning so that I can be able to debug.
In order to open the rails console in production, you can type:
RAILS_ENV=production bundle exec rails c
Or, if you want to debug code during runtime, you can use:
pry-remote
Rails 4 contains by default byebug and web-console. In development mode you can simply call byebug anywhere in the code to stop execution and get a debugger console.
In views you can use:
<%= console %>
to access an IRB console on exception pages.
See debugging guide.
If you don't have Rails 4, add to your Gemfile following:
group :development, :test do
gem 'byebug'
end
and run bundle install.
The official way to do this is using the byebug gem. Install it by executing
gem install byebug
After that you can put a byebug statement anywhere in your code:
class PeopleController < ApplicationController
def new
byebug
#person = Person.new
end
end
As soon as the application reaches this statement, it stops and presents a command prompt in the shell you started the server process.
See the RoR Debugging Guide for further details.

ByeBug Debugger working only once [Rails 4]

I'm having the problem that byebug class are ignored after the first one. It's very strange.
I start the server. Whenever there is a byebug statement, if it is the first one since the server has started, it will work. If not, it will say this message: *** Byebug already started. Ignoringbyebugcall. and the only way for the debugger to work would be to restart the server (and it will only work once).
Any help would be really appreciated.
BTW, this happens with every project.
Thanks.
This has been reported and fixed, but isn't in a release yet.
To work around for now you update your Gemfile with:
gem 'byebug', github: 'deivid-rodriguez/byebug', branch: 'master'
Then bundle update byebug and restart your Rails server.

How to I start a rails console with pry turned off?

Sometimes I have reason to want to start the rails console as an irb repl rather than pry (as awesome as pry is). It will default to pry because pry has in the Gemfile. Hows is that done nowadays?
I think there used to be a --irb option when running rails console but that seems to be gone now. I get a deprecation error message when I try it.
More details
If I just run "rails console" it takes me to pry.
If I run "rails console -irb=irb":
$ rails c -irb=irb
--irb option is no longer supported. Invoke `/your/choice/of/ruby script/rails console` instead
Relevent lines from my Gemfile:
gem 'rails', '3.2.18'
gem 'pry-rails'
gem 'pry-plus'
Launching pry when calling rails console or rails c is set up by the pry-rails gem. If you look in the pry-rails issues there is one that describes a solution.
Define the environment variable DISABLE_PRY_RAILS as 1.
So you can call rails console without pry with:
DISABLE_PRY_RAILS=1 rails c
Works in Rails 4: In your application.rb, inside your Application class, drop this puppy in.
# Use the IRB console instead of the Pry one
console do
require 'irb'
config.console = IRB
end
I couldn't take the Pry console anymore. It kept putting my cursor in odd places at unpredictable times. I can't even describe it but if you know what I'm talking about and know the solution, please let me know.
Inspired by the answers above, I added the following to the class definition in application.rb so that Pry is toggleable from the console:
console do
if ENV['IRB']
require 'irb'
config.console = IRB
end
end
You can then run rails c to get a Pry console, and IRB=true rails c to get an IRB console. This is easily modified if you want the inverse. Works in Rails 4 and 5.
For the benefit of anyone who runs into the same problem, this is my (crappy) workaround.
I wrapped the pry gems in Gemfile with this:
...
unless ENV['NOPRY']
gem 'pry-rails'
gem 'pry-plus'
end
...
Then run this from the unix terminal:
NOPRY=true bundle install
NOPRY=true rails console
Not pretty, but gets the job done...
You can also do it once console has already been started via IRB.start method.

Which gems do I need to debug a Rails application in RubyMine?

I use Ruby Mine 6.3, ruby 2.1 and Rails 4.0.3.
Which gems need to debug application with Ruby Mine, I tried use these gems:
gem 'debugger'
gem 'debugger-xml'
But application crashed with exit code 127 at breakpoint, and print this:
.rvm/gems/ruby-2.1.0/extensions/x86_64-linux/2.1.0/debugger-1.6.6/ruby_debug.so:
undefined symbol: rb_vm_get_sourceline
UPDATE
I updated RubyMine to 6.3.1, dropped 'debugger', 'debugger-xml' (in Gemfile only 'ruby-debug-ide') and Debugging works!
I advise bunch of "better_errors" and "binding_of_caller".
You can read about this here: https://github.com/charliesome/better_errors
I'm usually use this gems:
https://gist.github.com/MrEmelianenko/11078561
To enhance your console, use pry-rails, better with pry-doc.
To debug in program, like using breakpoint, step in/over, you can use pry-byebug or pry-debugger.
p.s. this is my way to debug rails app in terminal, I'm not sure if it is ok with Ruby Mine. Hope this can help.
I always liked pry. And its very useful with easy to learn screencast
This is my debugging stack for my Ruby 2 & Rails 3/4 apps ;)
group :development do
gem 'pry'
gem 'pry-nav'
gem 'pry-rescue'
gem 'pry-stack_explorer'
gem 'pry-doc'
end
Hope it helps
As you mentioned, you need ruby-debug-ide, but not debugger or debugger-xml.
For Rubymine/IDea + Ruby plugin with Ruby 2.0/2.1, also try the debase gem along with ruby-debug-ide to speed up debugging. Earlier versions had some trouble, but it works well, as of 2014-04-21.
You already found your answer but I'd like to add small notes
Rubymine has an issue with the debugger gem, or probably it's the gems clashing(maybe), rubymine uses fast-debugger (ruby-debug-ide) and I think it doesn't like debugger, old versions suggested adding debugger-xml but from my trials that didn't really work so well, and current version kinda tolerates debugger a bit, but sometimes it freezes during breakpoints.
My teammates use debugger, so it's pushed to the repo, what I do is whenever I need to debug I just delete the debugger line from my Gemfile and wait for rubymine to detect that Gemfile change (about a second or two) and start my debugging session, I only put it back when I check the diff before pushing.

Change default server for Rails

I installed the mongrel gem because I need it on my workstation for rare occasions, and now it's my default Rails (2) server. I know I could specify script/server webrick on the command line, but the fact is that I'd like to have my system (or app) default to webrick, and only use mongrel when specified.
Anybody know how to arrange that?
Specs: WinXP, Rails 2.3.12, Ruby 1.8.7
Ok here are a few options:
Option one - One off: Always add webrick as a command line arg
Open script/server and insert a line between the two requires
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
ARGV.unshift "webrick"
require 'commands/server'
Option two - Global: Edit the commands/server.rb file that launches rails
gem which railties -> tells you where the startup code is
Open the file at lib/commands/server.rb
Around line 45 edit the logic so that webrick is always launched by default.
server = Rack::Handler.get(ARGV.first) rescue nil
unless server
begin
server = Rack::Handler::WEBrick # was Mongrel
rescue LoadError => e
server = Rack::Handler::WEBrick
end
end
Option 3 - Cleanest but most involved:
Switch to Bundler and manage your dependencies directly. This is more work but positions you for switching to rails 3 at some point which might be nice depending on the life cycle of the application.
There's a tutorial for rails 2.3 here

Resources