ruby-on-rails – 为什么“rails s”从应用程序目录中工作?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 为什么“rails s”从应用程序目录中工作?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的应用程序文件夹,但是命令rails s不工作.我在Stack Overflow上阅读了不少帖子,大部分帖子似乎来自不在其应用目录中的用户.

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

输出轨道:

/Users/jmcrist/.rvm/gems/ruby-2.0.0-p247/bin/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新的).

根据您的版本,Rails标识不同.在3.2,它检查脚本/ rails的文件.现在4.0已经发布,它寻找脚本/轨道或bin / rails(https://github.com/rails/rails/blob/207fa5c11ddf1cfd696f0eeb07d6466aae9d451e/railties/lib/rails/app_rails_loader.rb#L6)

大概您可以通过在脚本目录中创建文件轨(如果没有脚本目录,在应用程序的根目录中创建一个脚本目录)可以解决此问题:

#!/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显示如何使用旧版本创建新应用程序).

原文链接:https://www.f2er.com/ruby/272585.html

猜你在找的Ruby相关文章