为什么没有“rails"?从应用程序目录工作? [英] Why doesn't "rails s" work from the app directory?

查看:62
本文介绍了为什么没有“rails"?从应用程序目录工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm in my app folder, but the command rails s is not working. I read through quite a few posts on Stack Overflow, and most of them seem to be from users who are not in their app directory.

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

In addition, I built a few other apps. I checked those, and the Rails server works for all of those apps. This is the only one where I can't get it to launch.

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 进行了很多修改.我想知道这可能是原因吗?

I'm working through Hartl's Rails Tutorial, and he makes quite a few modifications to the gemfile. I am wondering if this might be the cause?

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).

It seems to think you are not in a rails directory (your output is saying the only valid way to use rails is with rails new).

根据您的版本,Rails 会对此进行不同的识别.在 3.2 上,它会检查 script/rails 中的文件.现在 4.0 已经发布,它寻找 script/railsbin/rails (https://github.com/rails/rails/blob/207fa5c11ddf19f0eeb07d6466aae9d451e/railties/lib/rails/app_rails_loader.rb#L6" rel="noreferrer">https://github.com/rails/rails/blob/207fa5c11ddf19f0eeb07d6466aae9d451e/railties/lib/rails/app_rails_loader.rb#L6"/a>)

Depending on your version, Rails identifies this differently. On 3.2, it checks for a file at script/rails. Now that 4.0 has been released, it looks for either script/rails or bin/rails (https://github.com/rails/rails/blob/207fa5c11ddf1cfd696f0eeb07d6466aae9d451e/railties/lib/rails/app_rails_loader.rb#L6)

想必您可以通过在 script 目录中创建文件 rails 来解决这个问题(如果您没有 script 目录,请创建一个在您的应用的根目录中):

Presumably you can get around this by creating the file rails in your script directory (if you do not have a script directory, create one in the root of your app):

#!/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 如果版本较新,这篇 帖子将向您展示如何使用旧版本创建新应用.

Of course, it's worth wondering why you don't have this file in the first place. Might be worth making sure your rails is the version you want to be using first (rails -v if the version is newer, this post will show you how to create the new app using the older version).

这篇关于为什么没有“rails"?从应用程序目录工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆