ruby-on-rails - 为什么 "rails s"在 app 目录中不起作用?

标签 ruby-on-rails ruby gemfile

我在我的应用程序文件夹中,但命令 rails s 不起作用。我在 Stack Overflow 上阅读了很多帖子,其中大多数似乎来自不在其应用程序目录中的用户。

此外,我还构建了一些其他应用程序。我检查了那些,Rails 服务器适用于所有这些应用程序。这是唯一一个我无法启动它的地方。

which rails 的输出:

/Users/jmcrist/.rvm/gems/ruby-2.0.0-p247/bin/rails

rails s 的输出:

MacBook-Pro:first_app jmcrist$ rails s
Usage:
  rails new APP_PATH [options]

Options:
  -r, [--ruby=PATH]              # Path to the Ruby binary of your choice
                                 # Default: /Users/jmcrist/.rvm/rubies/ruby-2.0.0-p247/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.

我正在学习 Hartl 的 Rails 教程,他对 gemfile 做了很多修改。我想知道这是否可能是原因?

source 'https://rubygems.org'

gem 'rails', '3.2.13'

group :development do
  gem 'sqlite3', '1.3.5'
end


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.5'
  gem 'coffee-rails', '3.2.2'

  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.2'

group :production do
  gem 'pg', '0.12.2'
end

最佳答案

它似乎认为您不在 rails 目录中(您的输出表明使用 rails 的唯一有效方法是使用 rails new)。

根据您的版本,Rails 会以不同方式识别它。在 3.2 上,它检查位于 script/rails 的文件。现在 4.0 已经发布,它会寻找 script/railsbin/rails ( https://github.com/rails/rails/blob/207fa5c11ddf1cfd696f0eeb07d6466aae9d451e/railties/lib/rails/app_rails_loader.rb#L6 )

大概你可以通过在你的 script 目录中创建文件 rails 来解决这个问题(如果你没有 script 目录,创建一个在你的应用程序的根目录中):

#!/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'

当然,值得一提的是为什么您一开始就没有这个文件。可能值得确保您的 rails 是您首先要使用的版本(rails -v 如果版本较新,this 帖子将向您展示如何使用旧版本创建新应用程序).

关于ruby-on-rails - 为什么 "rails s"在 app 目录中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17645041/

相关文章:

ruby-on-rails - Rails 播种 boolean 值不起作用

.net - Web 开发期间自动刷新浏览器

ruby-on-rails - 在 Rails 中,如果不使用 Bundler,将 gem 卡住到项目中的最首选方法是什么?

ruby - 为什么这个启用 SSL 的 Ruby 服务器/客户端测试有效?

ruby-on-rails - 如何在 Rails 中获取 utc 偏移量?

ruby-on-rails - Capistrano 无法在应用程序部署中定位 Gemfile 错误

ruby-on-rails - 无法启动 rails 服务器或 rails 控制台

ruby-on-rails - before_save 如果 attribute.present?

ruby-on-rails - 如何在 Ruby on Rails 中获取人类可读的类名?

ruby-on-rails - Gemfile语法错误: gem 'turbolinks' ^ [closed]