哈特尔导轨教程第 3 部分 - 'rails generate controller'



我正在学习Michael Hartl的Rails教程,在第3.4节"生成静态页面控制器"中,我无法执行"rails生成控制器StaticPages家庭帮助"。当我键入命令时,我收到以下消息,看起来像是 rails 帮助消息:

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.

我还尝试了"rails 生成integration_test static_pages"只是为了看看会发生什么,它返回了相同的消息。不确定这是否意味着什么,但我想我会把它包括在这里。

当您在非 rails 项目的目录中运行 rails 命令(使用任何参数)时,会生成该响应。您要么没有正确创建 rails 项目,要么没有 cd 到项目中。

尝试重新创建 rails 项目。

如果在 Mac 或 Linux 上,键入 pwd 以获取当前工作目录。这是您预期的轨道应用程序的目录吗?如果没有,请 cd 进入它。

首先,最新的教程是遵循Ruby 2.0和Rails 4.0我不知道你为什么开始使用 Rails 3,但即使你这样做了,你也应该像下面这样做:

你应该遵循这样的事情。

  1. rails new myapp(然后切换到 MyApp 目录。

  2. rails generate controller Staticpages home help

(如果你不想自动生成测试文件,你可以最后添加--with-no-test-framework)

让宝石工作

  1. bundle install

休息已经在那里,希望你明白问题出在哪里

最新更新