Why Doesn't "Rails S" Work from the App Directory

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).

rails server' command not working in terminal

Change your current directory to the project directory and execute the rails server command.

example:

$rails new demo_app
$cd demo_app
$rails s

rails server command will start the server if you are inside a rails project directory. When you execute rails new demo_app it creates a directory called demo_app, which contains your new rails project. In your case rails server did not work because you are not inside demo_app directory.

rails s doesn't work but bundle exec rails s works. Why?

The purpose of having the bundle exec command is to look/search for the command which you want to run inside the current bundle or installed gems inside your vendor directory.

If you are running newer rails (v5) then have a look at the binstubs which copies over the command executeable in the bin directory. So that you can simply call

bin/rails server

This is the same approach which is followed by the deployment solutions which we currently have. They create a .bundle directory which eliminates the need to do bundle install everytime.

rails c wont work in app directory

I ran

$ bundle exec rake rails:update:bin 

that did the trick. And I had to add a boot file to the shared/config directory.

rails s doesn't work but bundle exec rails s works. Why?

The purpose of having the bundle exec command is to look/search for the command which you want to run inside the current bundle or installed gems inside your vendor directory.

If you are running newer rails (v5) then have a look at the binstubs which copies over the command executeable in the bin directory. So that you can simply call

bin/rails server

This is the same approach which is followed by the deployment solutions which we currently have. They create a .bundle directory which eliminates the need to do bundle install everytime.

Unable to start rails (s command does not exist)

After you run rails new appname, you need to cd appname before you can run server, console, etc. From your app root, you'll see a bin/rails, which is loaded when you're in your app directory and sets up all the app-specific commands via Rails::Commands. To avoid the opposite problem you're having, it also cleverly disallows creating a Rails app inside your Rails app.

rails server on existing working application not starting

In Rails 3.x, this will occur when script/rails is missing. The file could accidentally have been deleted or it may have never been committed to source control if you've just cloned the project to another machine. You'll need to find or regenerate it.

Rails determines if it's actually "in" a Rails project by checking if script/rails exists. If it doesn't find that file, it assumes it's not a Rails project:
https://github.com/rails/rails/blob/v3.2.21/railties/lib/rails/script_rails_loader.rb#L21-L23

There is an option you can pass 'rails new' to ignore files that already exist:

rails new APPNAME -s

You could try running that over your existing project to replace any missing files.

See also:
http://guides.rubyonrails.org/v3.2.13/initialization.html

Rails server does not start by command Rails s


  1. You need to create a new Rails app (unless you already have one)

    rails new my_app
  2. Go to your app directory

    cd my_app
  3. Start the server in that directory

    rails s


Related Topics



Leave a reply



Submit