Cannot access Rails console in Windows - LoadError - ruby-on-rails

I'm using JRuby because it's better for SRS Ruby on Rails, on Windows.
My solution was to use jirb in cmd.exe or Powershell (not gitbash).
I've tried:
$ rails console
Loading development environment (Rails 4.2.4)
Switch to inspect mode.
LoadError: load error: rails/commands -- java.lang.UnsatisfiedLinkError: The operation completed successfully.
require at org/jruby/RubyKernel.java:939
<top> at bin/rails:4
and:
$ bundle exec rails console
uri:classloader:/jruby/kernel/kernel.rb:17: warning: unsupported exec option: close_others
Loading development environment (Rails 4.2.4)
Switch to inspect mode.
LoadError: load error: rails/commands -- java.lang.UnsatisfiedLinkError: The operation completed successfully.
require at org/jruby/RubyKernel.java:939
<top> at bin/rails:4
and:
$ jruby.exe -S bundle exec rails console
uri:classloader:/jruby/kernel/kernel.rb:17: warning: unsupported exec option: close_others
Loading development environment (Rails 4.2.4)
Switch to inspect mode.
LoadError: load error: rails/commands -- java.lang.UnsatisfiedLinkError: The operation completed successfully.
require at org/jruby/RubyKernel.java:939
<top> at bin/rails:4
I tried the solution "Load error when running rails console", but restarting the computer has no effect. bin/spring has no mention of GEM_HOME. I reinstalled Rails and Spring.
Is this because of JRuby?
I'm entertaining the idea that jruby -S rails console requires C extensions. I found another way to access the console using JRuby's own jirc. I started with:
$ jirb
Switch to inspect mode.
then edited ~/.irbrc to include
IRB.conf[:PROMPT_MODE] = :SIMPLE
which produced:
$ jirb
Switch to inspect mode.
>>
which then immediately exits. Doing this:
$ jirb puts 'hello'
Switch to inspect mode.
Errno::ENOENT: No such file or directory - puts
initialize at org/jruby/RubyFile.java:342
open at org/jruby/RubyIO.java:1124
open at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb/magic-file.rb:7
initialize at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb/input-method.rb:100
initialize at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb/context.rb:84
initialize at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb.rb:426
start at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb.rb:381
<top> at G:/jruby-9.0.1.0/bin/jirb:13
Since my console is still not working and nothing about jirc is using C extensions, the question is not a duplicate to that one.

Yes, I would try and install jruby to resolve this
See http://jruby.org/getting-started
Then do bundle from the root of the project

TL;DR use jirb in Command Prompt to execute Ruby code.
I never resolved making rails console work. This may have to do with my ruby installation being a part of jRuby.
However, irb and jirb allow me to execute Ruby snippets on the command line with either Command Prompt or Powershell. GitBash doesn't work, says Switch to inspect mode. followed by >> and then exits.

Related

AppEngine Flexible Ruby environment, application startup error: /usr/bin/env: 'ruby2.5': No such file or directory

I'm trying to deploy an API-only Rails 5 application to AppEngine Flex w/ the standard Ruby runtime, and I'm getting the following error at the very end:
Updating service [default] (this may take several minutes)...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
/usr/bin/env: 'ruby2.5': No such file or directory
I'm specifying ruby '2.5.1' in my Gemfile and I've added an explicit .ruby-version file to the root of my project set to 2.5.1 as well.
I have no other debugging information available to me in the logs, no other fancieness. My entrypoint command is:
bundle exec rails server Puma -p $PORT
I can provide more details if needed, not sure what else might be relevant. Any pointers? As far as I can tell, nothing on my side is asking for a version of ruby that specifically at execution time.
Thanks!
EDIT: Here's my app.yaml file
entrypoint: bundle exec rails server Puma -p $PORT
env: flex
runtime: ruby
UPDATE:
I can verify that I'm having similar problems when trying to exec rake tasks like db:migrate:
--------- EXECUTE COMMAND ----------
bundle exec rake db:migrate
/usr/bin/env: 'ruby2.5': No such file or directory
ERROR
ERROR: build step 0 "gcr.io/google-appengine/exec-wrapper:latest" failed: exit status 127
--------------------------------------------------------------------------------------------------------------------------------------------------------
OK I now see what has happened after debugging the docker image locally. Because I was on ubuntu and had used system ruby to install gems it had embedded /usr/bin/env ruby2.5 into every executable script that was bundled into my app. I deleted all gems and switched to rbenv for managing Ruby version which mitigated this odd behavior between unbuntu's ruby and my app.

Running test from RubyMine gives 'cannot load such file'?

I have a test which runs as expected from the command line with:
bundle exec rake test TEST=test/my_test.rb
However, when I run the test from RubyMine I get:
require': cannot load such file -- my_test_helper_gem/test_helper (LoadError)
When I cmd+click on the require statement in my_test, RubyMine opens the expected source code. Any suggestions of how to resolve this? Possibly it works for the command line due to some magic related to rake?

Command: rails console, generate not recognize. Error: Command 'rails' not recognized Usage: rails COMMAND [ARGS]

When I go to rails folder (I'm inside my rails app folder) and type "rails c" or "rails g" it said:
Error: Command 'rails' not recognized
Usage: rails COMMAND [ARGS]
Usage: spring COMMAND [ARGS]
Commands for spring itself:
binstub Generate spring based binstubs. Use --all to generate a binstub for all known commands. Use --remove to revert.
help Print available commands.
server Explicitly start a Spring server in the foreground
status Show current status.
stop Stop all spring processes for this project.
Commands for your application:
rails Run a rails command. The following sub commands will use spring: console, runner, generate, destroy, test.
rake Runs the rake command
Error: Command 'rails' not recognized
Usage: rails COMMAND [ARGS]
The most common rails commands are:
generate Generate new code (short-cut alias: "g")
console Start the Rails console (short-cut alias: "c")
server Start the Rails server (short-cut alias: "s")
dbconsole Start a console for the database specified in config/database.yml
(short-cut alias: "db")
new Create a new Rails application. "rails new my_app" creates a
new application called MyApp in "./my_app"
In addition to those, there are:
destroy Undo code generated with "generate" (short-cut alias: "d")
plugin new Generates skeleton for developing a Rails plugin
runner Run a piece of code in the application environment (short-cut alias: "r")
All commands can be run with -h (or --help) for more information.
I'm running Linux Subsystem for Windows 10, I know I know you see Windows but it's kind of... Linux, and I installed Ruby by rbenv through this tutorial.
Try this command from your app folder:
rake rails:update:bin
Say y to replace the binaries.
I had the same problem using rails with Windows Linux Subsystem. I found the suggestion here:
Rails command Error
I tried it and it solved my problem, so maybe yours as well.
Even though the accepted answer solved your issue, I want to add another because I ran into the same error message but the underlying issue and my environment setup wasn't the same. However, recreating the executables in my app's bin folder did not solve the problem.
The issue: When I tried running bundle exec rails s or bundle exec rails c I got the same error as posted in the question. Using the apps executables worked fine though ./bin/rails s.
So the main differences from the question: I was using bundle exec when I got the error.
What was happening behind the scenes: bundle exec rails s was calling this executable /Users/robin/.rvm/gems/ruby-2.3.8/bin/rails which is shipped by the railties gem. I found this file was overwritten due to a gem which had an executable rails defined in its .gemspec.
What solved my problem:
Running $ bundle pristine railties (https://bundler.io/v2.0/man/bundle-pristine.1.html) so railties would be reset and with that the executable shipped by railties would overwrite the wrong one.
Addition: Of course it only helps as long as the intrusive gem shipping a rails executable is also updated and no longer wants it to be installed.

Cannot load Rails due to Switch to inspect mode error

I'm on a fresh install of Ubuntu 14.04 LTS. RVM 1.26.11 is installed with Ruby ruby 2.2.0p0. I'm using envconsul to handle environment variables. However, when I do:
envconsul -config=/etc/envconsul.hcl bundle exec rails c
it returns this error:
I, [2015-09-02T00:10:00.420551 #3953] INFO -- : ** [Raven] Raven 0.14.0 ready to catch errors
Loading development environment (Rails 4.2.3)
Switch to inspect mode.
and just dumps out to the command line. I can run bundle exec rails c on its own, but it fails out because the environment variables aren't set. I tried setting an ~/.irbrc but that doesn't help at all.
I'm really stumped on this one. Anyone have any ideas?
try following:
export $(envconsul -consul your_consul_server/agent -prefix your_app_env/ -upcase -pristine -once env)
and then:
ruby -S bundle exec /usr/local/bin/rails c
you can obviously include all these envconsul options in your *.hcl file.

Capistrano deploy fails with rake run (rails3 + rvm)

EDIT:
The issue here was that I used RVM on my local machine and rbenv on the server. This is highly not recommended, if you're managing several ruby installation (or upgrading your ruby version but do not want to change the system's) use either RVM or rbenv on all environments!
/EDIT
So I'll start with a bit history:
I'm in the process of upgrading our rails2 website to rails3. Most of the things are working properly by now, except Capistrano's deploy script.
The current setup I have is:
RVM (1.14.1) installed locally
ruby-1.9.3-p194 (set to the project's folder)
Capistrano v2.12.0 (upgraded from 2.6.0, but it doesn't work on 2.6.0 as well) installed as an RVM gem
rvm-capistrano (1.2.2), added to the Gemfile (after doing some reading online and on SO)
rbenv (with ruby 1.9.3p194 used globally) installed on the server
(by now if you see anything that doesn't make sense, please let me know)
Nothing changed in the deploy script, yet when I try to deploy to my testing server (let's call it beta) I get this error:
* executing `deploy:restart'
* executing "cd /home/foo/bar/current && rake RAILS_ENV=beta queue:restart_workers"
servers: ["208.0..."]
[208.0...] executing command
*** [err :: 208.0...] rake aborted!
*** [err :: 208.0...] no such file to load -- bundler/setup
*** [err :: 208.0...] /home/foo/bar/releases/20120630161947/Rakefile:5
*** [err :: 208.0...] (See full trace by running task with --trace)
** [out :: 208.0...] (in /home/foo/bar/releases/20120630161947)
command finished in 1183ms
failed: "sh -c 'cd /home/foo/bar/current && rake RAILS_ENV=beta queue:restart_workers'" on 208.0...
The relevant part on deploy.rb looks like this:
task :restart do
run "cd /home/foo/bar/current && rake RAILS_ENV=#{CAP_ENV} queue:restart_workers"
run "cd /home/foo/bar/current && rake RAILS_ENV=#{CAP_ENV} db:migrate"
run "touch #{deploy_to}/current/tmp/restart.txt"
end
Needless to say, rake RAILS_ENV=beta queue:restart_workers' works perfectly when run manually on the server. Also, the application gets deployed (the code was copied from git, it's just the last part of the deploy fails).
Lastly, the error didn't change since before I installed rvm-capistrano and added to the Gemfile, so I'm not even sure it's related to rvm, I'm just guessing from looking online.
Thanks
In order to work correctly, rbenv must override all the ruby and gem-related executables with the shims it provides.
Usually this is done with a startup script (this is why it works when you login to your server) but Capistrano logs in without shell and thus does not run those scripts.
You must add the following to your deploy.rb :
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
and do not use anything rvm related on your server, rbenv and rvm really do not like each other
PS : a little more explanation on this topic : http://henriksjokvist.net/archive/2012/2/deploying-with-rbenv-and-capistrano/

Resources