Which gems do I need to debug a Rails application in RubyMine? - ruby-on-rails

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.

Related

What's the replacement for acts_as_commentable in Rails 6, Ruby 3.0.2?

I upgraded our app to Rails 6.1.4.4 and Ruby 3.0.2. I have this old gem
gem 'acts_as_commentable'
Locked at version 4.0.2. The gem does not appear to be supported anymore, which is a shame because when I start up my app or console, I now get this error
$ rails c
Your Gemfile lists the gem rspec-rails (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
/Users/myuser/.rvm/gems/ruby-3.0.2/gems/hash_dot-2.5.0/lib/hash.rb:19:in `method_missing': undefined method `arity' for {:as=>:commentable, :dependent=>:destroy}:Hash (NoMethodError)
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:53:in `build_scope'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:47:in `create_reflection'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations/builder/association.rb:32:in `build'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/activerecord-6.1.4.4/lib/active_record/associations.rb:1458:in `has_many'
from /Users/myuser/.rvm/gems/ruby-3.0.2/gems/acts_as_commentable-4.0.2/lib/commentable_methods.rb:58:in `acts_as_commentable'
…
Is there any simple replacement for this gem or way to monkey-patch this error so I can start up the app?
Looking over the forks, I found this one that appears to work for me using Rails 6.0.6 and Ruby 3.0.5.
https://github.com/alazycoder101/acts_as_commentable.git
I have not tested it extensively yet, but at least the basic functionality seems to be working for me. Hope this helps.
For clarity, to use that fork you would use the following line in your Gemfile:
gem 'acts_as_commentable', git: 'https://github.com/alazycoder101/acts_as_commentable.git'

Rails: NoMethodError: undefined method `load_documents' for Psych:Module

I've been using the yaml_db gem for a long time to dump the database to yaml and then reload it later if needed. On a fresh project, though, on rake db:load I got the error message:
NoMethodError: undefined method `load_documents' for Psych:Module
Did you mean? load_stream
/Users/user/.rvm/gems/ruby-2.5.0/gems/yaml_db-0.6.0/lib/yaml_db.rb:61:in `load_documents'
I am submitting the solution I finally came up with as an answer, but I'm not really happy with it. If anyone has a better solution or a suggestion of something better than the yaml_db gem for dumping and reloading the database, I'd be happy to listen.
I'm running Rails 5.1.4 on Ruby 2.5.0
The solution I came up with was to put the 'psych' gem in my Gemfile before yaml_db and set it to an earlier release:
gem 'psych', '~> 2.2.1'
gem 'yaml_db'
This issue is caused by load_documents being deprecated in Psych and finally removed in ruby 2.5. There's an open PR on yaml_db that fixes this issue, so hopefully future versions will not require you to use this work-around.
Your current solution is probably the easiest for now (short of downgrading your ruby version, which is probably a worse idea).

What do I need to do to get the blog to work in rails 4.2?

I have just installed rails 4.2 . I have found this tutorial for making a quick blog: https://www.reinteractive.net/posts/32-ruby-on-rails-3-2-blog-in-15-minutes-step-by-step . However, it uses rails 3.2 . I have done everything that it says up to rake db:migrate and yet, when I run the server, I just get an error page. What has changed since 3.2? what do I now have to do to do the same thing?
error:
'ExecJS::ProgramError in Posts#index'
TypeError: Object doesn't support this property or method
(in C:/Ruby193/lib/ruby/gems/1.9.1/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)
EDIT:
On a side note, I can't even follow the official ruby on rails tutorial because when I run the server, after changing the root to root 'welcome#index' , I just get a page not found error.
Are there any tutorials for rails 4.2?
I had exactly the same ExecJS::ProgramError on Windows. The only solution that really helped was provided by KeithP here: Rails-4, ExecJS::ProgramError in Pages#welcome, i.e.,
Rollback to gem 'coffee-script-source', '1.8.0'.
There's some info here: ExecJS::RuntimeError in Users#index (RoR)
What I found when I looked into this problem was that in CoffeeScript there's a checkin here that I think broke things for Windows (under certain versions of the cscript runtime): https://github.com/jashkenas/coffeescript/blob/28c07d30cbd2add7ee762c7d532b2c9c972e441a/lib/coffee-script/parser.js
On line 563 it's doing an Object create(lexer) which fails with the error ActionView::Template::Error (TypeError: Object doesn't support this property or method.
Rolling back to CoffeeScript 1.8.0 (before this change) works around this problem. As others have stated in this answer and elsewhere, using a different runtime will workaround this problem too.
To roll back to CoffeeScript 1.8.0 add this to your gemfile:
gem 'coffee-script-source', '1.8.0'
And run these commands:
gem update 'coffee-script-source'
bundle update 'coffee-script-source'
Restart your server and it should be working.
This should solve your problem:
Add gem 'therubyracer', '~> 0.12.1' into your gemfile (or uncomment it - should be already there...)
Then run bundle install
Hope this helps.

Does RUBY on RAILS 4.0.2 work with MS SQL Server Express?

I've googled this to death and I'm just going around in circles.
I'm on a Windows Server 2008r
I installed and put the following in my Gemfile
gem 'ruby-odbc' # I think the version is the.9999 one?
gem 'tiny_tds', "~> 0.6.1"
gem 'activerecord-sqlserver-adapter' # I've tried a few versions of this 3.2.8 and 4.0
I get varying errors depending on how many times i've bundle installed or updated
Errors include activesupport and activerecord versions not found. They are installed
Or I get alias_method errors.
Can someone just point me in the right direction of what I should do. Some discussions seem to think that there is nothing that works at the moment. Would downgrading to an older Rails work? If so how and which version?
activerecord-sqlserver-adapter hasn't been released for Rails 4.0 yet but the gem is 95% ready. You can use put it in your Gemfile like this:
gem 'activerecord-sqlserver-adapter', github: 'rails-sqlserver/activerecord-sqlserver-adapter'
For a description of the outstanding work take a look at Failed Tests & Segfault on this pull request.

How to debug ruby code

I want to debug my Ruby code using the Ruby Mine IDE. In the drop down list Select Run/Debug Configuration, I chose My Project - development, then pressed Shift + F9. The Debugger started well, but did not stop at my break points. Why?
Ensure your Gemfile contains this:
gem 'linecache19', '>= 0.5.13', :git => 'https://github.com/robmathews/linecache19 0.5.13.git'
gem 'ruby-debug-base19x', '>= 0.11.30.pre12'
gem 'ruby-debug-ide', '>= 0.4.17.beta17'
maybe for details see that answer
Try using command line debugger: https://github.com/cldwalker/debugger
See also
http://railscasts.com/episodes/54-debugging-with-ruby-debug
http://railscasts.com/episodes/54-debugging-ruby-revised
pry is an interactive Ruby shell (or "REPL"), which can be used as a debugger (best combined with the pry-nav and pry-stack_explorer gems). It has a lot of features which make it much nicer to use than the debugger gem. For general exploration and experimentation with Ruby code, it's also nicer to use than irb.
For more info:
http://pryrepl.org/
https://github.com/pry/pry
After adding pry to your Gemfile and bundling, you can add a "breakpoint" with the following Ruby code: binding.pry

Resources