38

I typed this:

>rails console

and got this:

Usage:
  rails new APP_PATH [options]

Options:
      [--skip-gemfile]        # Don't create a Gemfile
  -d, [--database=DATABASE]   # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db)
                              # Default: sqlite3
..
..
.

I'm following along the rails tutorial and got stuck on this.

I have rails 3.0 installed.

Blankman
  • 259,732
  • 324
  • 769
  • 1,199
  • have you modified your bashrc (or bash_profile) file in any way? I once had this very same problem after modifying mine to display the current directory in my command prompt – stephenmurdoch Sep 19 '10 at 07:15

10 Answers10

41

In case anyone else hits this, my symptoms were:

I'd deployed my application with Capistrano 3

I cd'd into my application directory, and rails console didn't work

Turned out I'd included the bin folder as a symlinked directory in my cap deploy, as follows:

set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

... and my bin directory in 'shared' was empty.

Two fixes:

  • Ensure your linked bin directory has the correct contents (have a look inside your #{RAILS_ROOT}/bin directory for what this is, OR
  • Don't symlink bin

I then re-deployed and it works.

Guillaume Roderick
  • 1,139
  • 11
  • 12
  • You just saved me many hours of frustration. This was it exactly! – user2490003 Jun 10 '15 at 23:22
  • 1
    Thanks a lot! Clear and working instructions. It was extremely baffling for me since `bin` is actually empty and I was like "why would that change anything?" -- but it did. Thank you! – dimitarvp Nov 17 '15 at 15:16
  • 2
    Missing binstubs can be (re)generated using `bundle exec rake app:update:bin` (or `bundle binstubs ` for a specific gem). – Steve Sep 26 '19 at 19:45
39

Are you in the root path of your app when you type $ rails console?

Tip: $ rails c is a shortcut for $ rails console

Yannis
  • 5,426
  • 1
  • 31
  • 30
  • no I wasn't, but it works when I am, why is that? rails -v works outside the root path of the app. – Blankman Sep 19 '10 at 10:33
  • 4
    `rails` is a system-wide available program. You use it to set up your environment using `rails new `. In order to use rails commands specific to your application (like running the console), you have to tell it where to work - ie. running inside the project root. – eli Sep 19 '10 at 10:43
  • Also ensure you are using the same version of ruby that the project uses. – bradleygriffith Apr 16 '14 at 21:52
10

I just ran into this same problem while upgrading a Rails 2 app to Rails 3. When running rails console (or really rails [anything]) in my app's root directory, I would see general rails new usage output (as Blankman referenced in the original question).

The problem was that I had not removed the old Rails 2 scripts from the script directory. After removing everything in the script directory and adding the script/rails file that is auto-generated in each new Rails 3 app, the rails command now works as expected.

In order to get the latest contents of the script/rails file, generate a new app and copy the file into your Rails 2 app that you're upgrading. As of Rails 3.0.7, here's what's in this file:

#!/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'
Nick
  • 993
  • 9
  • 10
7

I had this problem when I upgraded Rails 2 to 3 and was able to fix it by doing what Nick said, then also running bundle exec rails console production.

Goro
  • 990
  • 8
  • 7
3

In Rails 2.3.x the command is script/console within a given Rails application directory to start a Ruby console with the default Rails environment loaded into memory. Not sure if Rails 3.0 is the same or not.

Richard Cook
  • 32,523
  • 5
  • 46
  • 71
2

You need to into the project directory and command rails console eg:

D:\workspace\>rails blog
D:\workspace\>cd blog
D:\workspace\blog\> rails c
loading en...
kenny
  • 56
  • 1
  • 4
1

are you in a rails 3 app directory?

do you have multiple versions of rails installed?

try checking 'which rails', and make sure this is a rails 3 executable you are running - that usage looks like rails 2.x.

Andrew Kuklewicz
  • 10,621
  • 1
  • 34
  • 42
1

You are running the correct command (rails console), but you are most likely not in the working directory for this application. Change directory to the root of your rails application (beneath which you will find /scripts, /app, etc.), and the command should work as desired.

Note: Using script/console or ruby script/console is for earlier versions of Rails.

eli
  • 645
  • 7
  • 15
0

In my case bin/rails c worked off my app root folder

Arthur
  • 1,441
  • 1
  • 13
  • 17
0

You need two gems "rdoc" and "rb-readline After that add this gems in Gemfile and bundle install Console is working fine

Arch-linux or Manjaro