RubyMine Rails script debugging, how to make lib classes visible - ruby-on-rails

I am trying to debug a script in my Rails project with RubyMine, but the script doesn't see classes that are defined under my lib dir.
The run/debug configuration is running the script in the context of bundle, but the visibility apparently isn't the same as if I had run "rails r script/foo.rb" from command line.
I have tried configuring the debug session to use Ruby script: rails, and then give r script/foo.rb as the script arguments. RubyMine does not accept this as a valid configuration.
Suggestions? My goal is to be able to interactively debug my rails context scripts as I already can do with code running in the rails server.
Here's the Console output RubyMine:
/home/michael/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -e at_exit{sleep(1)};$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /home/michael/.rvm/gems/ruby-1.9.3-p194/gems/ruby-debug-ide-0.4.17.beta14/bin/rdebug-ide --dispatcher-port 52376 --port 55139 -- /home/michael/work/myapp/script/foo.rb
Fast Debugger (ruby-debug-ide 0.4.17.beta14, ruby-debug-base 0.11.30.pre10) listens on 127.0.0.1:55139
Uncaught exception: uninitialized constant Foo::XLogger
/home/michael/work/myapp/script/foo.rb:17:in `go'
/home/michael/work/myapp/script/foo.rb:46:in `<top (required)>'
Process finished with exit code 0
XLogger is defined in /home/michael/work/myapp/lib/x_logger.rb.

I believe I have discovered my own answer/solution, but I offer it for anyone else having this same challenge.
In the Run/Debug Configurations
on the Configuration Tab
the Ruby script: field should be /path/to/rails/app/script/rails
the Script arguments: field should be r /path/to/rails/app/script/foo.rb

Related

After installing tailwindcss for ruby should I skip the following suggestions/warnings:

I tried to complete the first suggestion by typing
ruby
rails bin/dev
but I was not able to get an output (The terminal showed no output )
then I realized my code was wrong so I tried once again and typed:
rails create bin/dev
But it showed me an error and said "rails aborted!
Don't know how to build task 'create' (See the list of available tasks with rails --tasks)
Did you mean? db:create"
Then I tried the other command by typing rails in front of it but that didn't work either.
So even though my app works should I bother to solve this warning or skip past it?
TLDR: You need to build your CSS output on every Tailwind style addition so execute bin/dev in a terminal to start your rails server AND watch for tailwind changes.
Hey! Your screenshot is saying that you have successfully installed Tailwind via the tailwind-rails gem.
The end of the message provides instructions on how to build your Tailwind CSS during local development so that Tailwind styles are output to the CSS and applied to your app on localhost:3000 immediately.
Option 1: (documented in the installation output) In your terminal, execute bin/dev to start your rails server AND watch for tailwind changes. This command uses a library called foreman to run two processes, reading from the Procfile.dev that was created in your project's root directory during tailwind installation.
Option 2: (documented in this section of the README) In your terminal, execute rails s in one terminal window and rails tailwindcss:watch in a different window (separate commands)
Option 1 is simpler and probably recommended.
(Based on your screenshot, you are not on a Mac and your exact command may differ, but these work for me on a macbookpro.)

Rails runner does not find file, Rails version 5.1.3

I have a regular Rails project that is up and running fine, using Rails 5.1.3.
I recently discovered Rails runner and tried it along the documentation (https://guides.rubyonrails.org/command_line.html#rails-runner).
However, my Rails runner seems to be incapable of coping with files. I have a file lib/manual_exports/my_export.rb, and it really exists. I tried running
rails runner lib/manual_exports/my_export.rb
and
rails runner ./lib/manual_exports/my_export.rb
I always get the response
Please specify a valid ruby command or the path of a script to run.
Run 'bin/rails runner -h' for help.
undefined local variable or method `lib' for #<Rails::Command::RunnerCommand:0x00007fb13008b310>
# (or `.' instead of `lib')
This sounds as if runner thought my path was a Ruby command, which shouldn't be the case.
When I try reading in the file directly like
rails runner "eval(File.read 'lib/manual_exports/my_export.rb')"
or
rails runner "eval(File.read '#{Rails.root}/lib/manual_exports/my_export.rb')"
I get no answer at all, until I press ctrl+C, which gives me the stack trace
/Users/marion/.rvm/gems/ruby-2.4.2/gems/railties-5.1.3/lib/rails/commands/runner/runner_command.rb:37:in `read': No such file or directory # rb_sysopen - lib/manual_exports/my_export.rb (Errno::ENOENT)
I tried running a command directly (rails runner 'puts "hi"'), which worked. However, it took incredibly long - about two seconds. Can anybody explain to me what is happening here? Thank you!

Ruby system command fails Apache(Passenger)

Attempting to build statistics into a side project via Rserve- Everything works in testing and rails console but in production under:
apache(passenger), Rails 4, ruby-2.3.0.
the commands work in the rails console on the production box and I've confirmed that:
/bin/R is in the rails production (apache) path.
system "R CMD Rserve" works as expected in rails console on production host with production environment loaded
In production running Apache(Passenger):
system "R CMD Rserve" returns false
$?.inspect returns -> Process::Status: pid 11144 exit 2
The exit status 2 is throwing me off because it indicated a missing keyword or command, or permission problem.
Anybody run into this? I think the issue is in passenger but the limited output is making this hard to debug..

Can't turn off debugger in rails

I wanted to debug a test (MiniTest) in my Rails app. Therefore I followed the instruction on the Minitest-Debugger Github Page. Here is the important snippet:
Add this to the top of your test file or helper:
require 'minitest/debugger' if ENV['DEBUG']
Then run your tests as normal but define DEBUG=1:
% DEBUG=1 rake test
Debug.rb
Emacs support available.
Since then, all rails commands (like rails server or bundle exec rake test) I type into the console from my app directory try to start the debugger, which doesn't even work right but gives me some error messages from classes / parts outside my app.
% rails s
Debug.rb
Emacs support available.
/Users/chris/.rvm/gems/ruby-2.0.0-p353/gems/binding_of_caller-0.7.2/lib/binding_of_caller/mri2.rb:25: `' (NilClass)
How can I reset my environment / Rails / Ruby so it runs normally. I tried of course:
% DEBUG=0 rails s
But that didn't change anything. I deleted everything I set up in order to debug.
What do I have to do to stop Rails from entering debug-mode?

How to debug ruby tests in Eclipse/Aptana Studio?

is there a way to debug all/single tests in Aptana Studio / Eclipse?
ruby-debug19 & ruby-debug-ide are installed and I'm able to set breakpoints and debug my development environment, e.g. in a controller's index method. If I go to http://localhost:3000/controler_name eclipse opens debugging perspective and halts.
But how to do that with tests / rspec tests?
Thanks in advance.
For a normal ruby file, right click on it and select Debug As > Ruby application.
If your test is a rails one that requires some setup, or you want to debug the whole suite, you'll need to generate a debug configuration manually (or edit one manually).
Run > Debug As > Debug configurations... Then add an entry under Ruby application. Point it at your rake script path (say /usr/local/bin/rake) as the file to launch and then edit the arguments to pass in your app's Rakefile as the first arg and the rake task as the second arg. (i.e. /my/path/to/project/Rakefile tests)

Resources