Rails generate error: No such file or directory - getcwd - ruby-on-rails

When running rails generate on a new Rails 4.2 project, I keep getting the error:
~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.3.0/lib/spring/configuration.rb:37:in `pwd': No such file or directory - getcwd (Errno::ENOENT)
How can I fix this?

The error is caused by an existing Rails Spring process running in the background.
You can easily solve this by running ps ax | grep spring to find the process id and then kill it.
There's an issue on the Rails GitHub about this:
https://github.com/rails/spring/issues/247

This error may also occur if you are working in a directory which was deleted from some other terminal instance.

If the directory (or some sub directory Rails will work with) you are working was renamed or removed, you'll have to run
cd .
and then you can run rails generate [...].

On my machine the same problem was arising because spring server stopped responding.
1:- To restart the spring server type in terminal
$: spring restart
2:- Try running the generator again.

Related

Address already in use issue when running rails

Hi all I am new to rails and I am facing issue with running the rails app in WSL. I generated a new rails project and just set it up for deployment using capistrano. The deployment was successful. However, now I cant run rails locally. rails s gives me error.
I am posting the log here
I tried checking the port to see if any process was using port 3000 but it showed nothing. The commands that I tried are
lsof -wni tcp:3000
ps aux | grep puma
but they show no process that I can kill. I dont think this is an issue with WSL because I can run another newly created rails app.
Any help is highly appreciated. Thanks
I used to get this error too. I then realised that after I deleted the server.pid file found in either:
management\tmp\pids or > gateway\tmp\pids
and restarted the service, it ended up working.
I recommend you make a local copy of the file(s) in the pid folder incase you need it, then delete it, restart your service and see what happens.

why rails server is not working on windows 10

I have created the new rails project and trying to run it without doing any changes. I am using the power shell in windows 10. When I am running the rails s command its not starting the server. Please see attached image. I have highlighted the installed ruby version.
The error is there in the output, you do not have a rails app to start a server for, you can create a new app with:
rails new <name-for-your-app>
Follow along this tutorial
to help you get started with rails.
I think this command will work or you are missing something which is required to run rails server
bin/rails server
I've got similar error when I am not in rails project directory. Seems you are out of directory.
Please run those full commands in powershell
cd c:/
rails new testapp
cd testapp
rails s

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!

Running Webrick in Windows - Help getting started with Rails

I'm new to Ruby on Rails (and programming!) and am running through the guide here...
http://guides.rubyonrails.org/getting_started.html
However I am stumped on step 4.1. Creating a webserver as Webrick does not seem to run at all. Here is the error message that I see...
F:/Documents/Google Drive/Development/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4
.2.0/lib/rails/app_rails_loader.rb:39:in `exec': No such file or directory - "F:
/Documents/Google Drive/Development/Ruby21/bin/ruby.exe" (Errno::ENOENT)
The Ruby.exe does indeed exist in this location, all previous steps have been fine up until now. Any help would be much appreciated!
Is Ruby and Rails installed locally or is it in an external flash drive or cloud storage? You might need to reinstall everything into your C:\ drive to run a local server.
Also, did you copy the command from the guide verbatim? If you're running windows and using a cmd prompt, you don't need to include the "bin/" part of that command. Simply enter "rails server" or "rails s" for short to start the server.

cannot run rails server command for already created project

I have got an application which was zipped and I unzipped the files and it gave me a folder with all the required structure of a rails application. But when I am going inside the directory and running the rails server command, its not doing anything, but showing me the list of options rails command can do. What would have been the problem?
thanks
Maybe this will help from app folder try:
ruby script/rails server
As explained by Dave Isaacs, Showing the list of options is what the rails command does when it is executed outside the context of an application (i.e., not in the application directories).
Type the full command, including the /script path to the CLI.
script/rails server
instead of
rails server
where script is the path to the rails command that, in a Rails 3 application, lives in the script folder.
I would assume that the application you got was written with rails 2.x. In that case, you have to start it with
script/server

Resources