Break Point not working in Ruby 1.8.5?

I am not sure if this is an Instant Rails problem or something else.
But I am working with Patrick Lenz’s Building Your Own Ruby on Rails Web
Applications book where in Chapter 11 he shows how to use the BreakPoint
functionality within an RoR application. The book demonstrates this
functionality by setting a breakpoint in one of the Controller methods
as follows:

def new
@story = Story.new(params[:story])
@story.user = @current_user
if request.post? and @story.save
breakpoint
@story.tag_with params[:tags] if params[:tags]
flash[:notice] = ‘Story submission succeeded’
redirect_to :action => ‘index’
end
end

Now, the new action corresponds with a new story being submitted. As
the author instructs, I opened the web browser and try to submit a
story. The browswer is supposed to hang and I should be able to invoke
the breakpoint client by using the following command:

ruby script/breakpointer

But, the browswer displays the following information instead of hanging:

RuntimeError in StoryController#new

Breakpoints are not currently working with Ruby 1.8.5
RAILS_ROOT: ./script/…/config/…

Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/vendor/rails/railties/lib/breakpoint.rb:21:in of_caller' #{RAILS_ROOT}/vendor/rails/railties/lib/breakpoint.rb:543:inbreakpoint’
#{RAILS_ROOT}/app/controllers/story_controller.rb:12:in `new’

The breakpoint is indeed, on line 12 of the story_controller.rb file.

This puzzles me! How are people using InstantRails (I am using
InstantRails-1.5-win.zip). I also checked on the Ruby download website
which shows that the current version of Ruby is 1.8.5. Does it mean
that breakpoint functionality is not available in Ruby 1.8.5? Or this
particular release that I am working with does not have it?

Either way, please advise on how to go about solving this problem.

Bharat

On 3/22/07, Bharat R. [email protected] wrote:

I am not sure if this is an Instant Rails problem or something else.
But I am working with Patrick Lenz’s Building Your Own Ruby on Rails Web
Applications book where in Chapter 11 he shows how to use the BreakPoint
functionality within an RoR application. The book demonstrates this
functionality by setting a breakpoint in one of the Controller methods
as follows:

No, this is a known problem with Ruby 1.8.5.

Curt

This has something to do with the call_stack gem. Nevertheless, I find
ruby-debug far more productive. Give it a try.

I’ve never tried it on Windows, but it works like a charm on a Mac. If
you
do try it and it works on Win32, that would be good to know.

Mike-293 wrote:

@story = Story.new(params[:story])

the author instructs, I opened the web browser and try to submit a
RAILS_ROOT: ./script/…/config/…
InstantRails-1.5-win.zip). I also checked on the Ruby download website


View this message in context:
http://www.nabble.com/Break-Point-not-working-in-Ruby-1.8.5--tf3450316.html#a9627538
Sent from the RubyOnRails Users mailing list archive at Nabble.com.

I typically put the require statement at the top of the file under test,
but
in any case, I cranked this whole thing up in Parallels on my Mac and
repro’ed your error. Here’s how to fix it:

top of file

require ‘rubygems’ # not sure this is necessary
require ‘ruby-debug’
Debugger.start

Then someplace else in your program, put:

debugger

and you’ll have a breakpoint. I’d be curious to understand why this is
necessary.

Steve

Al Evans-2 wrote:

gem install c:\ruby-debug-base-0.8.1-mswin32.gem from the InstantRails
I get the following stacktrace and the server quits:
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require’
from


View this message in context:
http://www.nabble.com/Break-Point-not-working-in-Ruby-1.8.5--tf3450316.html#a9652789
Sent from the RubyOnRails Users mailing list archive at Nabble.com.

Thank you both gentlemen.
Steve, I am trying to install ruby-debug in InstantRails Windows
environment, but cannot get past the first base! I downloaded the
latest Windows specific build from RubyForge. The file is named
ruby-debug-base-0.8.1-mswin32.gem.

I installed this gem using the following command:

gem install c:\ruby-debug-base-0.8.1-mswin32.gem from the InstantRails
command window. Then I put the following line at the end of the
development.rb file which is under config\environments directory.

require ‘ruby-debug’

I saved the file and tried to start webrick by running the following
command:

ruby script/server webrick

I get the following stacktrace and the server quits:

C:\InstantRails\rails_apps\shovell-debug-02>ruby script/server webrick
=> Booting WEBrick…
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/commands/servers/webrick.rb:11:
warning: already initialized
constant OPTIONS
C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require': no such file to loa d -- ruby-debug (MissingSourceFile) from C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
from
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in
require' from ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:343:innew_constants_i
n’
from
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in
require' from ./script/../config/../config/environments/development.rb:22:inload_environment’
from
./script/…/config/…/vendor/rails/railties/lib/initializer.rb:204:in
load_environment' from ./script/../config/../vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:11:insil
ence_warnings’
from
./script/…/config/…/vendor/rails/railties/lib/initializer.rb:201:in
load_environment' ... 14 levels... from ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:496:inrequire’
from
./script/…/config/…/vendor/rails/railties/lib/commands/server.rb:39
from script/server:3:in `require’
from script/server:3

Does anyone else has had success installing ruby-debug in Windows
environment? The installation could not be simpler! I can see the
ruby-debug gem installed and gem command lists it as a locally installed
gem. What can be wrong?
Bharat

Success!
Thank you Steve for your patience. Here is/was the problem. I was
using the downloaded code from author’s site without much thinking, that
was the root cause.
Since Rails 1.2 was not officially released when the author created his
code, he had packaged various 1.2 rails components and installed them in
the vendors subdirectory of his example code. This is the same approach
taken by Agile Web… 2nd Edition. Now, this code base was at release
1.2.1 and it overrode the InstantRails more recent 1.2.2 code base.
Also, when I installed ruby-debug, it would go to the Instant Rail’s gem
lib directory under the “ruby” folder. This mismatch of rails versions
and misplacement of the gems was creating this problem.
I went back to ground zero. Created the sample app from scratch.
Copied author’s code folder by folder taking care not to copy-over any
rails 1.2.2 specific code, installed ruby-debug using gem install
command, put a breakpoint as directed in the link that you posted for
ruby-debug tutorial, and things are working just fine now!
Again, appreciate your help and patience.
Regards,
Bharat
p.s. In your experience, how well has ruby-debug worked compared to
script/breakpointer?

I do must of my debugging using logs. On the rare occasion when I need
to
examine something in a debugger, ruby-debug is far superior. Typically,
what
I would be looking at with a debugger are code paths and data state
changes,
neither of which breakpointer helps out with much.

–steve

Joshua M.-2 wrote:

1.2.1 and it overrode the InstantRails more recent 1.2.2 code base.
Bharat
p.s. In your experience, how well has ruby-debug worked compared to
script/breakpointer?


Posted via http://www.ruby-forum.com/.


View this message in context:
http://www.nabble.com/Break-Point-not-working-in-Ruby-1.8.5--tf3450316.html#a9661597
Sent from the RubyOnRails Users mailing list archive at Nabble.com.

How did you do the folder-by-folder copy? My copy of Winzip (V10)
refuses to open the gem file.

thanks…jon

Bharat… I found what I needed: the gem unpack command.

Sorry to bother you…thanks…jon

Steve… I’m also on InstantRails/Windows and tried the suggestions in
this thread… Two things:

  1. I had to add: require ‘ruby-debug-base’ to get this to work
  2. my ‘debugger’ command doesn’t make anything happen.

I tried it with and without the require ‘rubygems’ and that didn’t
make any difference.

Any thoughts as to what I’m doing wrong?

Thanks…jon

Any errors or just a quiet failure?

Also are you doing:

ruby script\server webrick

to get your app running?

To be honest, I don’t develop on Windows, so my test was on a hand-built
Ruby/MySQL/Rails install, not instant rails.

–steve

JESii wrote:

Then someplace else in your program, put:


View this message in context:
http://www.nabble.com/Break-Point-not-working-in-Ruby-1.8.5--tf3450316.html#a9662737
Sent from the RubyOnRails Users mailing list archive at Nabble.com.

Quiet failure; I’m running Mongrel, but it’s the same with webrick… I
saw
that you’re on Mac (nice setup; wish I were there :slight_smile:

Thanks, Steve… your feedback is much appreciated…jon

Thank you. Out of curiosity, may I ask what the issue was that caused
you to
break out the debugger? I’ve always been a fan of debuggers – that is,
until I began Rails programming. The combination of tests and the logger
has
been adequate for over 90% of my debugging needs.

–steve

Joshua M.-2 wrote:

window to pop-up. Instead, look at the command window from which you
p @story
primarily develop in linux, but there are times when I have to be in

Posted via http://www.ruby-forum.com/.


View this message in context:
http://www.nabble.com/Break-Point-not-working-in-Ruby-1.8.5--tf3450316.html#a9663098
Sent from the RubyOnRails Users mailing list archive at Nabble.com.

Hello Jon,
Here is what I did to debug the story_controller.rb file in the
aforementioned book:
I first installed the ruby-debug gem by executing the gem install
command.

Next, as Steve outlines above, I put the following three statements at
the top of the file.

top of the story_controller.rb file

require ‘rubygems’ # not sure this is necessary
require ‘ruby-debug’
Debugger.start

Then I put the debugger statement where I wanted the program to stop.
In my case it was in the new method right after the save statement.

Next, I fired up my browser(IE) and posted a new story. You should
notice the browswer to hang. At this point, do not expect a command
window to pop-up. Instead, look at the command window from which you
started the web server. I am using webrick by executing the command:
ruby script/server webrick
I will try it with Mongrel as well later and report my findings.

Look for the ruby debug prompt in the command window from where you
started the web server. Try to issue a simple “list” command to see if
the debugger indeed lists the source. If it works then try to display
the values of instance variables, or params hash using either “p” or
“pp” commands. For example, in my case I did the following:

p @story
or
pp @story

to print the params hash, do a similar command, i.e.

p params
or
pp params

The debugger is very unix/linux like in which no news is good news. I
primarily develop in linux, but there are times when I have to be in
Windows environment and therefore, I was looking to see if ruby and RoR
development is viable in it. I think that the InstantRails team has
done a fabulous job and made ruby and RoR on Windows machine an almost
usable alternative.

Let me know if this helps. Credit goes to Steve though.

Regards,
Bharat

Bharat… Thanks very much for getting back to me… here’s what is
happening.

  1. I followed the instructions you and Steve discussed. It failed for
    me,
    but I got it to work by requiring ‘ruby-debug-base’ instead.
  2. The require ‘rubygems’ is not necessary; I tried it both ways.
  3. No browser hang - it just goes about its normal behavior and nothing
    in
    the mongrel window.

I definitely agree with the assessment about InstantRails. I do have
some
issues with it, but they are relatively minor at this point. I wish I
could
say the same thing about RadRails which I do use, but which is
completely
broken for updates. At least what I have seems to be holding together
moderately well.

Thanks again…jon

Jon,
If you describe the steps that you are taking in more detail and more
importantly, what do you see when you do what, may be I can help you
pinpoint the problem. I do not understand “quiet failure”.
Steve,
I was merely, trying to explore all available options on Ruby on Rails.
I am just starting out with Ruby and RoR and try to explore various
things. I am still trying to get my head around writing more effective
tests and Patrick’s book has been invaluable on that topic. It is a
mental shift though.
I am glad that you brought up logs. Do you know an effective way of
viewing “formatted” log in Windows environment? In linux, the less
command does a great job of showing formatted entries. I have not been
able to replicate it in the Windows environment. I do not want to use
Cygwin since I have a dual boot machine and I can boot into Linux if I
want to.
Regards,
Bharat

I was having problems getting the right syntax to get the logger to work
for
me (wanted to look at some session variables)… I finally figured out
what
I was doing wrong and so now my logger stuff is working. At this point,
I
figured I’d just try to get the debugger working for whenever I might
need
it in the future. Actually not needed right this moment.

Cheers…jon

FYI… I’ve got MKS toolkit, which is very nice; having used that for
quite
some time, it’s a little hard to switch over to cygwin: I keep getting
bitten by cygwin’s c-drive references.

…jon

Bharat… “quiet failure” just means that nothing happened: no error
messages, no browser hang, no information in the server log.

BTW, I have read the Lenz book as well, along with two other books I am
working on: “Ruby for Rails” (David Black) and “Agile Web D.
with
Rails” (Thomas & Hanssen) - both very good.

Re “formatted log viewing” - I don’t know if this is what you mean, but
I
use vim (Vi Improved - www.vim.org). They have several really nice
plugins
for ruby/rails. If you’re a vim person (I’ve used it for many years),
then
you’ll love this software, and it’s free and very well supported.

Cheers…jon

yeah, cygwin would have been my recommendation. Really, all you are
looking
for is something with tail capabilities that understands terminal escape
sequences. I prefer to keep environments similar, where possible, so
cygwin
makes sense. That way, whether I’m on Windows or *nix, ls works, tail
works,
and so on.

Many Windows editors sense external modifications to files, but seldom
do
they put you at the end of the file automagically. Alternatively, just
write
a simple “tail” utility in C or Ruby (not very DRY :).

–steve

Joshua M.-2 wrote:

tests and Patrick’s book has been invaluable on that topic. It is a

Posted via http://www.ruby-forum.com/.


View this message in context:
http://www.nabble.com/Break-Point-not-working-in-Ruby-1.8.5--tf3450316.html#a9663329
Sent from the RubyOnRails Users mailing list archive at Nabble.com.