【问题标题】:rails generate controller command is not executedrails generate controller 命令未执行
【发布时间】:2014-08-11 21:57:36
【问题描述】:

我正在尝试使用以下命令在我的 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 控制台”也会返回相同的消息。我不明白为什么生成命令不起作用。

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

非常感谢您的帮助。

【问题讨论】:

  • 看起来您正在以Rails 2 或更低版本运行Rails 3 命令。您确定您的Rails 版本是3.2.13
  • 执行 'rails -v' 返回 Rails 3.2.13
  • 好吧,在Rails 2 中运行你的命令会为我返回相同的message
  • rails 命令行的版本不一定反映应用中安装的 rails 版本。要确保使用相同的版本,请尝试bundle exec rails ...。使用 bundle exec 为您的命令添加前缀会指示捆绑程序使用与您的应用程序捆绑的 gem 版本。如果你这样做,你仍然会得到同样的行为吗?

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


【解决方案1】:

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

当您尝试从应用程序目录运行生成控制器命令时,通常会出现此消息。

【讨论】:

  • 我在rails app目录中
  • 我已经尝试了相同的方法,并且仅在我超出应用程序目录时出现此错误。您正在使用 rails 3 或更高版本的另一件事。所以不用担心rails版本。如果你在 rails 2 中运行这个命令,那么它每次都会创建一个名为 generate 的新应用程序。
【解决方案2】:

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

cd blog
rails g controller posts

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2013-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-02
      相关资源
      最近更新 更多