ByeBug Debugger working only once [Rails 4] - ruby-on-rails

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.

Related

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.

Gem NameError when called from other gem

I'm trying to get PartyFoul set up on a Rails project I collaborate on and am running into a weird issue when I run the install generator.
~/.rvm/gems/.../party_foul-1.5.4/lib/generators/party_foul/install_generator.rb:21:in `rescue in create_initializer_file': uninitialized constant PartyFoul::InstallGenerator::Octokit (NameError)
from ~/.rvm/gems/.../gems/party_foul-1.5.4/lib/generators/party_foul/install_generator.rb:17:in `create_initializer_file'
The script is having trouble finding the Octokit gem so if I put require 'octokit' at the top of install_generator.rb, everything is happy. The weird part is that I can't replicate this issue on a clean Rails 4 or Rails 3.2 project that simply has PartyFoul installed, so it must be specific to this project, and while I can get the configuration file set up manually, I'd like to figure out what root cause of this problem is.
Any help would be much appreciated, thanks!
I just figured it out, the PartyFoul gem was in the :production group so I'm assuming that Rails was somehow not loading it properly. I replicated the NameError in the clean Rails project after moving the gem to :production, so that seems to be the difference. I'm not sure what the root cause is, any enlightenment would still be appreciated :-).

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.

First Heroku Push of Application to Heroku leads to Application Error

I am relatively new to Heroku and Rails. I have pushed a small "app" to Heroku before which worked fine.
Now I have developed a bit of a larger application on my desktop pc, which runs fine using my rails server as localhost.
When I try migrating it to Heroku I get the following message:
Application Error
=================
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
I started looking at the log files, but they don't really tell me anything. Can someone please give me a hint on how to interpret them. I think the last to logfile lines are the ones that crash the application:
2013-08-12T17:54:56.944875+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/bundler-1.3.2/lib/bundler/rubygems_integration.rb:224:in `block in replace_gem': can't activate bcrypt-ruby (~> 3.0.0), already activated bcrypt-ruby-3.1.1. Make sure all dependencies are added to Gemfile. (Gem::LoadError)
EDIT: I've now added the complete 'heroku logs' prompt output. Any suggestions on what to look for. I'm very unfamiliar with the log output, don't really know where to start.
EDIT 2: Thanks for all the help so far! I've got the app working now. The following was the problem
In my gem file I had ByCrypt linked in like this:
gem 'bcrypt-ruby', :require => 'bcrypt'
Since the Heroku logs said something about
can't activate bcrypt-ruby (~> 3.0.0), already activated bcrypt-ruby-3.1.1.
I changed my Gemfile to
gem 'bcrypt-ruby', '~> 3.0.0'
This helped! The app is now running on heroku. But I think I now have a problem with the methods using bcrypt... but I will have to investigate this seperately. Thanks for the help!
have you migrated the database?
like this: heroku run rake db:migrate
if that dosn't work use this:
run heroku logs, and paste the log here
2013-08-12T17:54:56.944875+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/bundler-1.3.2/lib/bundler/rubygems_integration.rb:224:in `block in replace_gem': can't activate bcrypt-ruby (~> 3.0.0), already activated bcrypt-ruby-3.1.1. Make sure all
dependencies are added to Gemfile. (Gem::LoadError)
maybe you forgot to add a gem explicity in your gemfile,

NameError in PostsController#pingback

This is my first time trying to get a Gem to work in rails where I haven't just been able to follow the documentation.
I first installed the gem using sudo gem install ping back and then added it to my Gemfile via gem 'pingback'. I then ran bundle install and it shows it installed in the list it outputs.
So then I wrong a little function that looks like this and is in my posts controller:
def send_trackback(posts)
posts.each do |post|
source_uri = "http://example.com/posts/#{post.slug_url}"
target_uri = post.target_url
Pingback::Client.new.ping(source_uri, target_uri)
end
end
whenever I try to load the admin page that sends the trackbacks I get the following:
NameError in PostsController#pingback
uninitialized constant PostsController::Pingback
Do I have to do more than just install the gem via bundler and then plug and play?
Update
adding require 'pingback' to the top of my posts controller results in this:
cannot load such file -- pingback
The error message to me indicates that the VM is trying to find PingBack in PostsController, I am thinking you are missing a require or include statement for PingBack.
It may be a typo, but pingback needs to be one word, not 'ping back' for the line in the gemfile, and for the gem install.
I would try running 'bundle list' to make sure the gem is installed.
I restarted the rails server and I believe this has resolved this issue.

Resources