Why doesn't "rails s" work from the app directory?
It seems to think you are not in a rails directory (your output is saying the only valid way to use rails is with rails new
).
Depending on your version, Rails identifies this differently. On 3.2, it checks for a file at script/rails
. Now that 4.0 has been released, it looks for either script/rails
or bin/rails
(https://github.com/rails/rails/blob/207fa5c11ddf1cfd696f0eeb07d6466aae9d451e/railties/lib/rails/app_rails_loader.rb#L6)
Presumably you can get around this by creating the file rails
in your script
directory (if you do not have a script
directory, create one in the root of your app):
#!/usr/bin/env ruby# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.APP_PATH = File.expand_path('../../config/application', __FILE__)require File.expand_path('../../config/boot', __FILE__)require 'rails/commands'
Of course, it's worth wondering why you don't have this file in the first place. Might be worth making sure your rails is the version you want to be using first (rails -v
if the version is newer, this post will show you how to create the new app using the older version).
Possible reasons:
- you are not in a directory that contains a full rails app
- your
bin
directory might me empty, try to runrake rails:update:bin
(for Rails 4) orrails app:update:bin
(Rails 5)
All the above answers didn't help me. What solved my problem for Rails 4
was to run command in the root directory of my application:
rake rails:update:bin
After that running rails s
was running as expected.