v7.0.0
更多資訊請前往 rubyonrails.org: 更多在 Ruby on Rails

Rails 命令列

閱讀本指南後,您將瞭解:

本教程假設您透過閱讀 Rails 入門指南 具有基本的 Rails 知識。

1 命令列基礎

有一些命令對您日常使用 Rails 至關重要。按照你可能會使用它們的順序是:

  • bin/rails console
  • bin/rails server
  • bin/rails test
  • bin/rails generate
  • bin/rails db:migrate
  • bin/rails db:create
  • bin/rails routes
  • bin/rails dbconsole
  • rails new app_name

透過鍵入 rails --help,您可以獲得可用的 rails 命令列表,這些命令通常取決於您的當前目錄。每個命令都有一個描述,應該可以幫助你找到你需要的東西。

$ rails --help
Usage: rails COMMAND [ARGS]

The most common rails commands are:
 generate    Generate new code (short-cut alias: "g")
 console     Start the Rails console (short-cut alias: "c")
 server      Start the Rails server (short-cut alias: "s")
 ...

All commands can be run with -h (or --help) for more information.

In addition to those commands, there are:
 about                               List versions of all Rails ...
 assets:clean[keep]                  Remove old compiled assets
 assets:clobber                      Remove compiled assets
 assets:environment                  Load asset compile environment
 assets:precompile                   Compile all the assets ...
 ...
 db:fixtures:load                    Loads fixtures into the ...
 db:migrate                          Migrate the database ...
 db:migrate:status                   Display status of migrations
 db:rollback                         Rolls the schema back to ...
 db:schema:cache:clear               Clears a db/schema_cache.yml file
 db:schema:cache:dump                Creates a db/schema_cache.yml file
 db:schema:dump                      Creates a database schema file (either db/schema.rb or db/structure.sql ...
 db:schema:load                      Loads a database schema file (either db/schema.rb or db/structure.sql ...
 db:seed                             Loads the seed data ...
 db:version                          Retrieves the current schema ...
 ...
 restart                             Restart app by touching ...
 tmp:create                          Creates tmp directories ...

讓我們建立一個簡單的 Rails 應用程式來在上下文中逐步執行這些命令。

1.1 rails new

我們要做的第一件事是在安裝 Rails 後執行 rails new 命令來建立一個新的 Rails 應用程式。

資訊:您可以透過鍵入 gem install rails 來安裝 rails gem,如果您還沒有的話。

$ rails new commandsapp
     create
     create  README.md
     create  Rakefile
     create  config.ru
     create  .gitignore
     create  Gemfile
     create  app
     ...
     create  tmp/cache
     ...
        run  bundle install

Rails 將為您設定一個看似龐大的內容來處理如此微小的命令!現在您已經獲得了整個 Rails 目錄結構,其中包含開箱即用執行我們的簡單應用程式所需的所有程式碼。

如果您希望跳過生成的某些檔案或元件,您可以將以下引數附加到您的 rails new 命令:

引數 說明
--skip-git 跳過 .gitignore 檔案
--skip-keeps 跳過原始碼管理 .keep 檔案
--skip-action-mailer 跳過Action Mailer 檔案
--skip-action-text 跳過 Action Text gem
--skip-active-record 跳過 Active Record 檔案
--skip-active-storage 跳過 Active Storage 檔案
Action Cable 跳過 Action Cable 檔案
--skip-sprockets 跳過鏈輪檔案
--skip-javascript 跳過 JavaScript 檔案
--skip-turbolinks 跳過 turbolinks gem
--skip-test 跳過測試檔案
--skip-system-test 跳過系統測試檔案
--skip-bootsnap 跳過 bootsnap gem

1.2 bin/rails server

bin/rails server 命令啟動一個名為 Puma 的 Web 伺服器,它與 Rails 捆綁在一起。每當您想透過 Web 瀏覽器訪問您的應用程式時,您都可以使用它。

無需進一步的工作,bin/rails server 將執行我們新的閃亮的 Rails 應用程式:

$ cd commandsapp
$ bin/rails server
=> Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.5.7-p206), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop

只需三個命令,我們就啟動了一個 Rails 伺服器,監聽埠 3000。轉到瀏覽器並開啟 http://localhost:3000,您將看到一個基本的 Rails 應用程式正在執行。

資訊:您還可以使用別名“s”來啟動伺服器:bin/rails s

伺服器可以使用 -p 選項在不同的埠上執行。可以使用 -e 更改預設開發環境。

$ bin/rails server -e production -p 4000

-b 選項將 Rails 繫結到指定的 IP,預設情況下它是 localhost。您可以透過傳遞 -d 選項將伺服器作為守護程式執行。

1.3 bin/rails generate

bin/rails generate 命令使用模板來建立很多東西。單獨執行 bin/rails generate 會給出可用生成器的列表:

資訊:您還可以使用別名“g”來呼叫生成器命令:bin/rails g

$ bin/rails generate
Usage: rails generate GENERATOR [args] [options]

...
...

Please choose a generator below.

Rails:
  assets
  channel
  controller
  generator
  ...
  ...

您可以透過生成器 gems 安裝更多生成器,您無疑會安裝部分外掛,甚至可以建立自己的!

使用生成器可以透過編寫 樣板程式碼(應用程式執行所需的程式碼)為您節省大量時間。

讓我們用 controller 生成器製作我們自己的 controller。但是我們應該使用什麼命令呢?讓我們問生成器:

資訊:所有 Rails 控制檯實用程式都有幫助文字。與大多數 *nix 實用程式一樣,您可以嘗試在末尾新增 --help-h,例如 bin/rails server --help

$ bin/rails generate controller
Usage: bin/rails generate controller NAME [action action] [options]

...
...

Description:
    ...

    To create a controller within a module, specify the controller name as a path like 'parent_module/controller_name'.

    ...

Example:
    `bin/rails generate controller CreditCards open debit credit close`

    Credit card controller with URLs like /credit_cards/debit.
        Controller: app/controllers/credit_cards_controller.rb
        Test:       test/controllers/credit_cards_controller_test.rb
        Views:      app/views/credit_cards/debit.html.erb [...]
        Helper:     app/helpers/credit_cards_helper.rb

controller 生成器需要 generate controller ControllerName action1 action2 形式的引數。讓我們用 hello 的 action 製作一個 Greetings controller,這會對我們說些好話。

$ bin/rails generate controller Greetings hello
     create  app/controllers/greetings_controller.rb
      route  get 'greetings/hello'
     invoke  erb
     create    app/views/greetings
     create    app/views/greetings/hello.html.erb
     invoke  test_unit
     create    test/controllers/greetings_controller_test.rb
     invoke  helper
     create    app/helpers/greetings_helper.rb
     invoke    test_unit

這一切產生了什麼?它確保我們的應用程式中有一堆目錄,並建立了一個 controller 檔案、一個 view 檔案、一個功能測試檔案、一個 view 的 helper、一個 JavaScript 檔案和一個樣式表文件。

檢視 controller 並稍微修改一下(在 app/controllers/greetings_controller.rb 中):

class GreetingsController < ApplicationController
  def hello
    @message = "Hello, how are you today?"
  end
end

然後是 view,顯示我們的訊息(在 app/views/greetings/hello.html.erb 中):

<h1>A Greeting for You!</h1>
<p><%= @message %></p>

使用 bin/rails server 啟動您的伺服器。

$ bin/rails server
=> Booting Puma...

URL 將是 http://localhost:3000/greetings/hello

資訊:對於普通的普通 Rails 應用程式,您的 URL 通常遵循 http://(host)/(controller)/(action) 的模式,以及類似 http://(host)/(controller) 的 URL ) 將命中該 controller 的 index action。

Rails 也帶有一個數據生成器 models。

$ bin/rails generate model
Usage:
  bin/rails generate model NAME [field[:type][:index] field[:type][:index]] [options]

...

ActiveRecord options:
      [--migration], [--no-migration]        # Indicates when to generate migration
                                             # Default: true

...

Description:
    Generates a new model. Pass the model name, either CamelCased or
    under_scored, and an optional list of attribute pairs as arguments.

...

有關 type 引數的可用欄位型別列表,請參閱 API 文件,瞭解 SchemaStatements module 的 add_column 方法。 index 引數為該列生成相應的索引。

但不是直接生成 model(我們稍後會做),讓我們設定一個 scaffold。 Rails 中的 scaffold 是一套完整的 model,資料庫 migration 用於 model,controller 用於操作它,views 用於檢視和操作資料,以及上述每個的測試套件。

我們將設定一個名為“HighScore”的簡單資源,用於記錄我們玩的影片遊戲的最高分。

$ bin/rails generate scaffold HighScore game:string score:integer
    invoke  active_record
    create    db/migrate/20190416145729_create_high_scores.rb
    create    app/models/high_score.rb
    invoke    test_unit
    create      test/models/high_score_test.rb
    create      test/fixtures/high_scores.yml
    invoke  resource_route
     route    resources :high_scores
    invoke  scaffold_controller
    create    app/controllers/high_scores_controller.rb
    invoke    erb
    create      app/views/high_scores
    create      app/views/high_scores/index.html.erb
    create      app/views/high_scores/edit.html.erb
    create      app/views/high_scores/show.html.erb
    create      app/views/high_scores/new.html.erb
    create      app/views/high_scores/_form.html.erb
    invoke    test_unit
    create      test/controllers/high_scores_controller_test.rb
    create      test/system/high_scores_test.rb
    invoke    helper
    create      app/helpers/high_scores_helper.rb
    invoke      test_unit
    invoke    jbuilder
    create      app/views/high_scores/index.json.jbuilder
    create      app/views/high_scores/show.json.jbuilder
    create      app/views/high_scores/_high_score.json.jbuilder

生成器檢查是否存在 models、controllers、helpers、佈局、功能和單元測試、樣式表的目錄,為 HighScore 建立 views、控制器、模型和資料庫 migration(建立 ZHTZW_0_W 的路徑,負責欄位) 資源,以及所有新測試。

migration 要求我們遷移,即執行一些 Ruby 程式碼(位於 20130717151933_create_high_scores.rb 中)來修改我們資料庫的架構。哪個資料庫?當我們執行 bin/rails db:migrate 命令時,Rails 將為您建立的 SQLite3 資料庫。我們將在下面詳細討論該命令。

$ bin/rails db:migrate
==  CreateHighScores: migrating ===============================================
-- create_table(:high_scores)
   -> 0.0017s
==  CreateHighScores: migrated (0.0019s) ======================================

資訊:讓我們談談單元測試。單元測試是測試和做出斷言的程式碼 關於程式碼。在單元測試中,我們取一小部分程式碼,比如說一個 model 的方法, 並測試其輸入和輸出。單元測試是你的朋友。越早做 當你團結起來時,你的生活質量會大大提高 測試你的程式碼,更好。嚴重地。請拜訪 測試指南 深入 看看單元測試。

讓我們看看 Rails 為我們建立的介面。

$ bin/rails server

轉到您的瀏覽器並開啟 http://localhost:3000/high_scores,現在我們可以建立新的高分(Space Invaders 上的 55,160!)

1.4 bin/rails console

console 命令允許您從命令列與 Rails 應用程式互動。在底部,bin/rails console 使用 IRB,因此如果您曾經使用過它,那麼您就會感到賓至如歸。這對於使用程式碼測試快速想法和在不接觸網站的情況下更改伺服器端資料非常有用。

資訊:您還可以使用別名“c”來呼叫控制檯:bin/rails c

您可以指定 console 命令應在其中執行的環境。

$ bin/rails console -e staging

如果您希望在不更改任何資料的情況下測試某些程式碼,您可以透過呼叫 bin/rails console --sandbox 來實現。

$ bin/rails console --sandbox
Loading development environment in sandbox (Rails 7.0.0)
Any modifications you make will be rolled back on exit
irb(main):001:0>
1.4.1 應用程式和 helper 物件

bin/rails console 中,您可以訪問 apphelper 實例。

使用 app 方法,您可以訪問命名路由 helpers,以及執行請求。

irb> app.root_path
=> "/"

irb> app.get _
Started GET "/" for 127.0.0.1 at 2014-06-19 10:41:57 -0300
...

使用 helper 方法可以訪問 Rails 和應用程式的 helpers。

irb> helper.time_ago_in_words 30.days.ago
=> "about 1 month"

irb> helper.my_custom_helper
=> "my custom helper"

1.5 bin/rails dbconsole

bin/rails dbconsole 確定您正在使用哪個資料庫,並將您放入您將使用的任何命令列介面(並確定要提供給它的命令列引數!)。它支援 MySQL(包括 MariaDB)、PostgreSQL 和 SQLite3。

資訊:您還可以使用別名“db”來呼叫 dbconsole:bin/rails db

如果您使用多個數據庫,預設情況下 bin/rails dbconsole 將連線到主資料庫。您可以使用 --database--db 指定要連線到的資料庫:

$ bin/rails dbconsole --database=animals

1.6 bin/rails runner

runner 在 Rails 上下文中以非互動方式執行 Ruby 程式碼。例如:

$ bin/rails runner "Model.long_running_method"

資訊:您還可以使用別名“r”來呼叫執行程式:bin/rails r

您可以使用 -e 開關指定 runner 命令應在其中執行的環境。

$ bin/rails runner -e staging "Model.long_running_method"

您甚至可以使用執行程式執行編寫在檔案中的 ruby 程式碼。

$ bin/rails runner lib/code_to_be_run.rb

1.7 bin/rails destroy

destroy 視為 generate 的對立面。它會弄清楚 generate 做了什麼,然後撤消它。

資訊:您還可以使用別名“d”來呼叫銷燬命令:bin/rails d

$ bin/rails generate model Oops
      invoke  active_record
      create    db/migrate/20120528062523_create_oops.rb
      create    app/models/oops.rb
      invoke    test_unit
      create      test/models/oops_test.rb
      create      test/fixtures/oops.yml
$ bin/rails destroy model Oops
      invoke  active_record
      remove    db/migrate/20120528062523_create_oops.rb
      remove    app/models/oops.rb
      invoke    test_unit
      remove      test/models/oops_test.rb
      remove      test/fixtures/oops.yml

1.8 bin/rails about

bin/rails about 提供有關 Ruby、RubyGems、Rails、Rails 子元件、應用程式資料夾、當前 Rails 環境名稱、應用程式資料庫介面卡和架構版本的版本號的資訊。當您需要尋求幫助、檢查安全補丁是否會影響您時,或者當您需要現有 Rails 安裝的一些統計資訊時,它非常有用。

$ bin/rails about
About your application's environment
Rails version             6.0.0
Ruby version              2.7.0 (x86_64-linux)
RubyGems version          2.7.3
Rack version              2.0.4
JavaScript Runtime        Node.js (V8)
Middleware:               Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, ActiveSupport::Cache::Strategy::LocalCache::Middleware, Rack::MethodOverride, ActionDispatch::RequestId, ActionDispatch::RemoteIp, Sprockets::Rails::QuietAssets, Rails::Rack::Logger, ActionDispatch::ShowExceptions, WebConsole::Middleware, ActionDispatch::DebugExceptions, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, Rack::Head, Rack::ConditionalGet, Rack::ETag
Application root          /home/foobar/commandsapp
Environment               development
Database adapter          sqlite3
Database schema version   20180205173523

1.9 bin/rails assets:

您可以使用 bin/rails assets:precompile 預編譯 app/assets 中的資產,並使用 bin/rails assets:clean 刪除較舊的編譯資產。 assets:clean 命令允許在構建新資產時滾動部署可能仍連結到舊資產。

如果想徹底清除public/assets,可以使用bin/rails assets:clobber

1.10 bin/rails db:

db: rails 名稱空間中最常見的命令是 migratecreate,嘗試所有 migration rails 命令(updown、ZHTW_5_WTH6_WTHZ)是值得的。 bin/rails db:version 在故障排除時很有用,告訴您資料庫的當前版本。

有關遷移的更多資訊,請參見 Migrations 指南。

1.11 bin/rails notes

bin/rails notes 在您的程式碼中搜索以特定 key 字開頭的註釋。使用方法可以參考bin/rails notes --help

預設情況下,它會在appconfigdblibtest目錄與擴充套件.builder.rb.rake.yml.yaml.ruby.css.js.erb檔案搜尋FIXME,最佳化和TODO註釋。

$ bin/rails notes
app/controllers/admin/users_controller.rb:
  * [ 20] [TODO] any other way to do this?
  * [132] [FIXME] high priority for next deploy

lib/school.rb:
  * [ 13] [OPTIMIZE] refactor this code to make it faster
  * [ 17] [FIXME]
1.11.1 註釋

您可以使用 --annotations 引數傳遞特定的註釋。預設情況下,它將搜尋 FIXME、OPTIMIZE 和 TODO。 請注意,註釋區分大小寫。

$ bin/rails notes --annotations FIXME RELEASE
app/controllers/admin/users_controller.rb:
  * [101] [RELEASE] We need to look at this before next release
  * [132] [FIXME] high priority for next deploy

lib/school.rb:
  * [ 17] [FIXME]
1.11.2 標籤

您可以使用 config.annotations.register_tags 新增更多要搜尋的預設標籤。它接收一個標籤列表。

config.annotations.register_tags("DEPRECATEME", "TESTME")
$ bin/rails notes
app/controllers/admin/users_controller.rb:
  * [ 20] [TODO] do A/B testing on this
  * [ 42] [TESTME] this needs more functional tests
  * [132] [DEPRECATEME] ensure this method is deprecated in next release
1.11.3 目錄

您可以使用 config.annotations.register_directories 新增更多要搜尋的預設目錄。它接收目錄名稱列表。

config.annotations.register_directories("spec", "vendor")
$ bin/rails notes
app/controllers/admin/users_controller.rb:
  * [ 20] [TODO] any other way to do this?
  * [132] [FIXME] high priority for next deploy

lib/school.rb:
  * [ 13] [OPTIMIZE] Refactor this code to make it faster
  * [ 17] [FIXME]

spec/models/user_spec.rb:
  * [122] [TODO] Verify the user that has a subscription works

vendor/tools.rb:
  * [ 56] [TODO] Get rid of this dependency
1.11.4 擴充套件

您可以使用 config.annotations.register_extensions 新增更多要搜尋的預設副檔名。它接收一個擴充套件列表及其相應的正則表示式以匹配它。

config.annotations.register_extensions("scss", "sass") { |annotation| /\/\/\s*(#{annotation}):?\s*(.*)$/ }
$ bin/rails notes
app/controllers/admin/users_controller.rb:
  * [ 20] [TODO] any other way to do this?
  * [132] [FIXME] high priority for next deploy

app/assets/stylesheets/application.css.sass:
  * [ 34] [TODO] Use pseudo element for this class

app/assets/stylesheets/application.css.scss:
  * [  1] [TODO] Split into multiple components

lib/school.rb:
  * [ 13] [OPTIMIZE] Refactor this code to make it faster
  * [ 17] [FIXME]

spec/models/user_spec.rb:
  * [122] [TODO] Verify the user that has a subscription works

vendor/tools.rb:
  * [ 56] [TODO] Get rid of this dependency

1.12 bin/rails routes

bin/rails routes 將列出您定義的所有路由,這對於跟蹤您的應用中的路由問題很有用,或者為您提供一個很好的超過view 的應用中的網址,您正在嘗試熟悉。

1.13 bin/rails test

資訊:A Guide to Testing Rails Applications 中對 Rails 中的單元測試進行了很好的描述

Rails 帶有一個名為 minitest 的測試框架。 Rails 的穩定性歸功於測試的使用。 test: 名稱空間中可用的命令有助於執行您希望編寫的不同測試。

1.14 bin/rails tmp:

Rails.root/tmp 目錄與 *nix /tmp 目錄一樣,是臨時檔案(如程序 ID 檔案和快取的 actions)的存放位置。

tmp: 名稱空間命令將幫助您清除和建立 Rails.root/tmp 目錄:

  • bin/rails tmp:cache:clear 清除 tmp/cache
  • bin/rails tmp:sockets:clear 清除 tmp/sockets
  • bin/rails tmp:screenshots:clear 清除 tmp/screenshots
  • bin/rails tmp:clear 清除所有快取、sockets 和螢幕截圖檔案。
  • bin/rails tmp:create 為快取、sockets 和 pid 建立 tmp 目錄。

1.15 雜項

  • bin/rails initializers 按照 Rails 呼叫的順序打印出所有定義的初始化器。
  • bin/rails middleware 列出為您的應用啟用的機架中介軟體堆疊。
  • bin/rails stats 非常適合檢視程式碼的統計資訊,顯示 KLOC(數千行程式碼)和程式碼與測試比率之類的內容。
  • bin/rails secret 會給你一個偽隨機 key 用於你的 session 秘密。
  • bin/rails time:zones:all 列出了 Rails 知道的所有時區。

1.16 自定義 Rake 任務

自定義 rake 任務有一個 .rake 副檔名並被放置在 Rails.root/lib/tasks。您可以使用 bin/rails generate task 命令。

desc "I am short, but comprehensive description for my cool task"
task task_name: [:prerequisite_task, :another_task_we_depend_on] do
  # All your magic here
  # Any valid Ruby code is allowed
end

將引數傳遞給您的自定義 rake 任務:

task :task_name, [:arg_1] => [:prerequisite_1, :prerequisite_2] do |task, args|
  argument_1 = args.arg_1
end

您可以透過將任務放在名稱空間中來對任務進行分組:

namespace :db do
  desc "This task does nothing"
  task :nothing do
    # Seriously, nothing
  end
end

任務的呼叫將如下所示:

$ bin/rails task_name
$ bin/rails "task_name[value 1]" # entire argument string should be quoted
$ bin/rails "task_name[value 1,value2,value3]" # separate multiple args with a comma
$ bin/rails db:nothing

如果您需要與您的應用程式 models 進行互動、執行資料庫查詢等,您的任務應該依賴於 environment 任務,它會載入您的應用程式程式碼。

2 Rails 高階命令列

命令列的更高階用法側重於在實用程式中找到有用的(有時甚至令人驚訝)選項,並使這些選項適合您的需求和特定的工作流程。這裡列出了一些 Rails 袖手旁觀的技巧。

2.1 帶有資料庫和 SCM 的 Rails

建立新的 Rails 應用程式時,您可以選擇指定應用程式將使用的資料庫型別和原始碼管理系統型別。這將為您節省幾分鐘,當然還有很多 keystrokes。

讓我們看看 --git 選項和 --database=postgresql 選項將為我們做什麼:

$ mkdir gitapp
$ cd gitapp
$ git init
Initialized empty Git repository in .git/
$ rails new . --git --database=postgresql
      exists
      create  app/controllers
      create  app/helpers
...
...
      create  tmp/cache
      create  tmp/pids
      create  Rakefile
add 'Rakefile'
      create  README.md
add 'README.md'
      create  app/controllers/application_controller.rb
add 'app/controllers/application_controller.rb'
      create  app/helpers/application_helper.rb
...
      create  log/test.log
add 'log/test.log'

在 Rails 將它建立的檔案新增到我們的儲存庫之前,我們必須建立 gitapp 目錄並初始化一個空的 git 儲存庫。讓我們看看它在我們的資料庫設定中放了什麼:

$ cat config/database.yml
# PostgreSQL。支援 9.3 及更高版本。
#
#安裝pg驅動:
# gem 安裝 pg
# 在帶有 Homebrew 的 macOS 上:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# 在帶有 MacPorts 的 macOS 上:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# 在 Windows 上:
# gem 安裝 pg
# 選擇 win32 版本。
# 安裝 PostgreSQL 並將其 /bin 目錄放在您的路徑中。
#
# 使用 Gemfile 設定
#寶石'pg'
#
default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # https://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: gitapp_development
...
...

它還在我們的 database.yml 設定中生成了一些行,對應於我們為資料庫選擇的 PostgreSQL。

筆記。使用 SCM 選項的唯一問題是您必須首先建立應用程式的目錄,然後初始化您的 SCM,然後您可以執行 rails new 命令來生成您的應用程式的基礎。

回饋

我們鼓勵您幫助提高本指南的品質。

如果您發現任何拼寫錯誤或資訊錯誤,請提供回饋。 要開始回饋,您可以閱讀我們的 回饋 部分。

您還可能會發現不完整的內容或不是最新的內容。 請務必為 main 新增任何遺漏的文件。假設是 非穩定版指南(edge guides) 請先驗證問題是否已經在主分支上解決。 請前往 Ruby on Rails 指南寫作準則 查看寫作風格和慣例。

如果由於某種原因您發現要修復的內容但無法自行修補,請您 提出 issue

關於 Ruby on Rails 的任何類型的討論歡迎提供任何文件至 rubyonrails-docs 討論區