rails generate controller命令未执行

时间:2014-08-11 11:19:27

标签: ruby-on-rails ruby-on-rails-3.2

我正在尝试使用以下命令在我的rails应用程序中生成一个控制器:

rails generate controller CreditCard

但它只是返回以下内容:

Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]              # Path to the Ruby binary of your choice
                                 # Default: /export/data0/home/tanya/.rvm/rubies/ruby-1.9.3-p448/bin/ruby
  -b, [--builder=BUILDER]        # Path to a application builder (can be a filesystem path or URL)
  -m, [--template=TEMPLATE]      # Path to an application template (can be a filesystem path or URL)
      [--skip-gemfile]           # Don't create a Gemfile
      [--skip-bundle]            # Don't run bundle install
  -G, [--skip-git]               # Skip Git ignores and keeps
  -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
      [--old-style-hash]         # Force using old style hash (:foo => 'bar') on Ruby >= 1.9

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.

即使运行'rails console'也会返回相同的消息。我不明白为什么generate命令不起作用。

我目前正在使用rails 3.2.13和ruby 1.9.3。

非常感谢你的帮助。

3 个答案:

答案 0 :(得分:1)

我认为你不在rails应用程序目录中。请再次检查路径和运行命令。

当您尝试从应用程序目录中运行generate controller命令时,通常会出现此消息。

答案 1 :(得分:1)

我认为您没有在Rails根目录中运行该命令。您必须在运行rails生成器之前导航到该应用程序。如果您有一个名为blog的应用程序,请按照以下命令

cd blog
rails g controller posts

答案 2 :(得分:0)

非常感谢您的所有建议。我所做的只是使用rails new new_app创建一个新的应用程序,并将我原来的rails应用程序的文件复制到这个新目录。 在我这样做之后,似乎工作正常。我一定搞砸了原始应用程序文件夹中的内容。