0
votes

I'm working through Michael Hartl's Rails Tutorial, and in section 3.4- 'Generating a StaticPages controller', I'm unable to execute 'rails generate controller StaticPages home help'. When I type the command, I get the following message that looks to be a rails help message:

Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]              # Path to the Ruby binary of your choice
                                 # Default: /usr/local/rvm/rubies/ruby-1.9.3-p484/bin/ruby
  -m, [--template=TEMPLATE]      # Path to some application template (can be a filesystem path or URL)
      [--skip-gemfile]           # Don't create a Gemfile
  -B, [--skip-bundle]            # Don't run bundle install
  -G, [--skip-git]               # Skip .gitignore file
      [--skip-keeps]             # Skip source control .keep files
  -O, [--skip-active-record]     # Skip Active Record files
  -S, [--skip-sprockets]         # Skip Sprockets files
  -d, [--database=DATABASE]      # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
                                 # Default: sqlite3
  -j, [--javascript=JAVASCRIPT]  # Preconfigure for selected JavaScript library
                                 # Default: jquery
  -J, [--skip-javascript]        # Skip JavaScript files
      [--dev]                    # Setup the application with Gemfile pointing to your Rails checkout
      [--edge]                   # Setup the application with Gemfile pointing to Rails repository
  -T, [--skip-test-unit]         # Skip Test::Unit files
      [--rc=RC]                  # Path to file containing extra configuration options for rails command
      [--no-rc]                  # Skip loading of extra configuration options from .railsrc file

Runtime options:
  -f, [--force]    # Overwrite files that already exist
  -p, [--pretend]  # Run but do not make any changes
  -q, [--quiet]    # Suppress status output
  -s, [--skip]     # Skip files that already exist

Rails options:
  -h, [--help]     # Show this help message and quit
  -v, [--version]  # Show Rails version number and quit

Description:
    The 'rails new' command creates a new Rails application with a default
    directory structure and configuration at the path you specify.

    You can specify extra command-line arguments to be used every time
    'rails new' runs in the .railsrc configuration file in your home directory.

    Note that the arguments specified in the .railsrc file don't affect the
    defaults values shown above in this help message.

Example:
    rails new ~/Code/Ruby/weblog

    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
    See the README in the newly created application to get going.

I also tried 'rails generate integration_test static_pages' just to see what would happen, and it returned the same message. Not sure if that means anything, but I thought I'd include it here.

3
did you create the rails application? - alex
Even if you did create app as @alex wrote, check if you actually cded into it (i.e. check if you're in your app root). - zrl3dx
Yes, I created the rails app and was working from the sample_app directory. - user3163541
Which version of Rails are you using? - zrl3dx
Can you attach the output of ls in dir where you're running rails g command? - zrl3dx

3 Answers

0
votes

That response is generated when you run the rails command (with any args) in a directory that is not a rails project. You either did not create the rails project correctly, or you did not cd into the project.

Try recreating the rails project.

0
votes

if on Mac or Linux, type pwd to get the current working directory. Is this the directory of your intended rails app? If not, cd into it.

0
votes

First of all Latest tutorial is following Ruby 2.0 and Rails 4.0 I don't know why you have started with Rails 3 but even if you do, you should be doing like below:

You should follow something like this.

  1. rails new myapp(then switch to myapp dir.)

  2. rails generate controller Staticpages home help

(you can add --with-no-test-framework at last if you don't want a test file to be generated automatically)

for Gem to work

  1. bundle install

Rest is already there , I hope you understood where is the problem