Cannot start rails console unless spring is disabled - ruby-on-rails

My rails development environment runs in Docker, and I cannot start the rails console without disabling spring using DISABLE_SPRING=true. The snipper below illustrates what happens:
app#docker:[project] $ bundle exec rails c
Could not find rake-13.0.6 in any of the sources
Run `bundle install` to install missing gems.
app#docker:[project] $ DISABLE_SPRING=true bundle exec rails c
D, [2022-01-19T03:44:17.663136 #20] DEBUG -- sentry: initialized a background worker with 6 threads
Loading development environment (Rails 6.1.4.4)
irb(main):001:0>
I've tried rebuilding my docker image from scratch, deleting the Gemfile.lock and building again. Nothing works, except for disabling spring.
Surprisingly, rails server works fine.
Any ideas?

Related

Is there a way to connect to a Rails app's console on a linux server?

I have deployed a rails application using capistrano on a linux server and it is running without any problems. When I connect to my remote server via ssh, the folder structure of my app is quite different from what I have on my local machine. I would like to go to project root and say rails console so that I can have access to the console of my application. Is there a way to achieve this?
When I go to ~MyApp/ folder and run rails console it says command rails not found. I think that is probably because the app is running in another folder.
bundle exec to the rescue inside of project folded:
$ RAILS_ENV=production bundle exec rails console
If you've installed with rbenv it could be that you are defaulting to the wrong Ruby version. So you can run rbenv exec to get it to run on the right version, along with bundle exec to run the right version of Rails
So try running this:
rbenv exec bundle exec rails console
To sum up for anyone having the same problem in the future,
I went to MyApp/releases/2020331231231231 which is the latest release of my app and there I used this command RAILS_ENV=production bundle exec rails console and I was able to do whatever I wanted to do in the console.
First you need to move inside the folder where the code is.
Check Capistrano config if deploy_to is defined. (If it's not it should be set to /var/www/#{application}/ by default read here)
Since Capistrano keep older versions of your app go to the current folder which is a symlink of the latest deployed version.
And run ENVIRONMENT=production bundle exec rails c or ENVIRONMENT=production bin/rails c. If doesn't work try with rbenv ENVIRONMENT=production rbenv exec bundle exec rails c

The localhost page isn’t working ruby rails puma osx

I have been working on a rails app for months and then, all of a sudden the pumas server does not work on my laptop. I've tried different older branches (in case I changed something) I've uninstalled and reinstalled ruby. Nope. It DOES work if I do a fresh pull and load it on my desktop, so it seems to be something on my laptop? I am really lost.
Here's what I've done already:
Restarted the computer
reinstalled ruby
Tried puma
Tried rails s
Tried different branches to see if something I did yesterday somehow broke it
reinstalled gems
The error is:
The localhost page isn’t working
localhost didn’t send any data.
However, right before it was running this error, it ran a Request time out error, if that matters.
What I really don't understand is why it's only happening on one computer.
I am running Ruby 2.3.0 and rails 4.2.6
UPDATE
It DOES running rails server and not puma.
The problem is, I'm using foreman to start sidekiq with my server, and that's how I debug sidekiq queues. Strangely, sidekiq still works, but I can't access the localhost page.
This is my procfile:
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -c 2 -q default -q mailers
Again, I haven't changed anything with puma and rails s works fine.

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.

Unable to run `rails g` or `rails c` without `sudo`

I am unable to run rails g or rails c, because of the following error message:
Could not find mysql2-0.3.18 in any of the sources
Run `bundle install` to install missing gems.
I can run 'rails server', which works fine, as expected. I also have ran bundle install, with no errors (this line is in my Gemfile: gem 'mysql2'). The database works fine with rails server, but seems to break with rails g/c.
Update:
I can run rails g and rails c with sudo. I think it's a problem with my path - I think I might have installed MySQL as root.
Have you tried running those commands using Bundler?
bundle exec rails c
bundle exec rails g

Resources