加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 20:04:09 所属栏目:百科 来源:网络整理
导读:我在我的应用程序文件夹,但是命令rails s不工作.我在Stack Overflow上阅读了不少帖子,大部分帖子似乎来自不在其应用目录中的用户. 另外我建了一些其他的应用程序.我检查了这些,Rails服务器适用于所有这些应用程序.这是唯一一个我无法启动的地方. 输出轨道:
我在我的应用程序文件夹,但是命令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将显示如何使用旧版本创建新应用程序).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读