首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么"rails s“不能在app目录下工作?

为什么"rails s“不能在app目录下工作?
EN

Stack Overflow用户
提问于 2013-07-15 08:10:39
回答 6查看 20.1K关注 0票数 19

我在我的应用程序文件夹中,但命令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
EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2013-07-15 13:00:08

它似乎认为您不在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 post将向你展示如何使用旧版本创建新的应用程序)。

票数 28
EN

Stack Overflow用户

发布于 2014-10-02 16:27:34

以上所有的答案对我都没有帮助。解决Rails 4问题的方法是在我的应用程序的根目录中运行命令:

rake rails:update:bin

在那之后,运行的rails s就像预期的那样运行了。

票数 8
EN

Stack Overflow用户

发布于 2017-03-16 23:46:51

例如,如果您使用rvmrbenv来保留多个ruby版本,则该特定rails版本的默认ruby版本可能与您试图运行的项目不同,因此它无法检测到您的应用程序。

为了确保您使用的是正确的rails版本,您可以比较这两个结果。这就是我得到的:

$ rails -v
Rails 3.1.0

$ bundle exec rails -v
Rails 5.0.0.1

在这种情况下,您可以保留默认的rails版本,然后使用:

$ bundle exec rails server

或者使用以下命令将特定的rails gem安装到该ruby版本:

$ gem install rails -v 5.0.0.1
$ rails -v
Rails 5.0.0.1

然后使用不太详细的命令使其正常工作:

$ rails s

我希望这能对其他遇到同样情况的人有所帮助!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17645041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档