2013-07-15 24 views
15

我在我的應用程序文件夾中,但命令rails s不起作用。我閱讀了Stack Overflow上的很多帖子,其中大部分似乎來自不在其應用目錄中的用戶。爲什麼「rails s」不能從app目錄中運行?

此外,我建了一些其他的應用程序。我檢查了這些,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. 

我通過哈特爾的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 
+0

命令欄服務器的工作?編輯〜在SO中查看其他類似的問題,可能是因爲你沒有安裝或更新你的寶石,嘗試進行捆綁安裝或捆綁更新 –

+0

命令行中'pwd'的輸出是什麼? – zeantsoi

+0

'/ Users/jmcrist/rails_projects/first_app' – jmcrist

回答

22

它似乎覺得你是不是在一個軌道目錄(您的輸出是說的唯一有效的方式來使用軌道是rails new) 。

根據您的版本,Rails可以區別這一點。在3.2上,它在script/rails處檢查文件。現在4.0已經發布,它看起來要麼script/railsbin/railshttps://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 -v如果版本更新,this後會告訴你如何使用舊版本創建新的應用程序)。

+0

你完全正確 - 我使用了錯誤的Rails版本。 我遵循Michael Hartl的教程,無論什麼原因,當我離開並回過頭後,我偶然選擇了Rails 3.2版本。 謝謝你的幫助! – jmcrist

+0

謝謝!我使用的應用程序起初是作爲Rails 4應用程序開始的,但我最終降級了。因此'bin/rails'文件夾丟失了,我使用了pow,所以在我想使用控制檯之前這個問題是隱藏的。正在抓我的頭,重建rvm gemsets和各種直到我看到這個! – Pezholio

+0

謝謝!這節省了一天。 – David

1

您可能還沒有綁定的寶石還沒有:

# from command line 
bundle install 
+0

zeantsoi:我試圖做到這一點。不幸的是,它沒有解決問題: '...你的包是完整的! 集團生產中的寶石沒有安裝。 使用'bundle show [gemname]'查看捆綁的gem的安裝位置。 MacBook Pro:first_app jmcrist $ rails s 用法: rails新APP_PATH [選項] ...' – jmcrist

+0

我遇到與OP相同的問題。束尚未到達路徑。 – Kirka121

18

可能的原因:

  • 你是不是在包含一個完整的Rails應用程序的目錄
  • bin目錄可能我空,嘗試運行rake rails:update:bin(爲Rails 4)或rails app:update:bin(Rails的5)
+0

我用'spring binstub -all'弄亂了我的bin目錄,這爲我恢復了它。 –

+0

我已經丟棄了bin目錄,記得把它們放在git上 – juliangonzalez

+0

爲我工作。謝謝! –

7

所有上述答案沒有幫助我。有什麼解決我的問題了Rails 4是在我的應用程序的根目錄下運行命令:

rake rails:update:bin 

跑跑rails s後,正在按預期運行。

0

我有這個問題,花了我幾分鐘才意識到我忘記了用chruby來改變活動的Ruby版本。不同的Ruby意味着不同的Rails版本,它在另一個文件夾中查找相關文件。

0

首先檢查您的位置路徑,然後

bundle install 

如果仍然不能正常工作,輸入

/bin/bash --login 
bundle install 
0

如果使用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 

我希望這將成爲有利於在相同情況下其他人!