1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #38789 from hahmed/docs/bin-rails-updates

Remove reference to global rails command
This commit is contained in:
Eugene Kenny 2020-04-12 01:36:44 +01:00 committed by GitHub
commit 2998672fc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 74 additions and 110 deletions

View file

@ -447,7 +447,7 @@ module ActiveRecord
# It's possible to set the fixture's model class directly in the YAML file.
# This is helpful when fixtures are loaded outside tests and
# +set_fixture_class+ is not available (e.g.
# when running <tt>rails db:fixtures:load</tt>).
# when running <tt>bin/rails db:fixtures:load</tt>).
#
# _fixture:
# model_class: User

View file

@ -329,7 +329,7 @@ db_namespace = namespace :db do
pending_migrations.each do |pending_migration|
puts " %4d %s" % [pending_migration.version, pending_migration.name]
end
abort %{Run `rails db:migrate:#{name}` to update your database then try again.}
abort %{Run `bin/rails db:migrate:#{name}` to update your database then try again.}
end
end
end

View file

@ -133,10 +133,10 @@ connection specification name.
Now that we have the `database.yml` and the new model set up it's time to create the databases.
Rails 6.0 ships with all the rails tasks you need to use multiple databases in Rails.
You can run `rails -T` to see all the commands you're able to run. You should see the following:
You can run `bin/rails -T` to see all the commands you're able to run. You should see the following:
```bash
$ rails -T
$ bin/rails -T
rails db:create # Creates the database from DATABASE_URL or config/database.yml for the ...
rails db:create:animals # Create animals database for current environment
rails db:create:primary # Create primary database for current environment
@ -166,10 +166,10 @@ rails db:structure:load:animals # Recreates the animals database from t
rails db:structure:load:primary # Recreates the primary database from the structure.sql file
```
Running a command like `rails db:create` will create both the primary and animals databases.
Running a command like `bin/rails db:create` will create both the primary and animals databases.
Note that there is no command for creating the users and you'll need to do that manually
to support the readonly users for your replicas. If you want to create just the animals
database you can run `rails db:create:animals`.
database you can run `bin/rails db:create:animals`.
## Migrations

View file

@ -114,18 +114,18 @@ If you wish to skip some files or components from being generated, you can appen
| `--skip-system-test` | Skip system test files |
| `--skip-bootsnap` | Skip bootsnap gem |
### `rails server`
### `bin/rails server`
The `rails server` command launches a web server named Puma which comes bundled with Rails. You'll use this any time you want to access your application through a web browser.
The `bin/rails server` command launches a web server named Puma which comes bundled with Rails. You'll use this any time you want to access your application through a web browser.
With no further work, `rails server` will run our new shiny Rails app:
With no further work, `bin/rails server` will run our new shiny Rails app:
```bash
$ cd commandsapp
$ bin/rails server
=> Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `rails server --help` for more startup options
=> 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
@ -136,7 +136,7 @@ Use Ctrl-C to stop
With just three commands we whipped up a Rails server listening on port 3000. Go to your browser and open [http://localhost:3000](http://localhost:3000), you will see a basic Rails app running.
INFO: You can also use the alias "s" to start the server: `rails s`.
INFO: You can also use the alias "s" to start the server: `bin/rails s`.
The server can be run on a different port using the `-p` option. The default development environment can be changed using `-e`.
@ -146,7 +146,7 @@ $ bin/rails server -e production -p 4000
The `-b` option binds Rails to the specified IP, by default it is localhost. You can run a server as a daemon by passing a `-d` option.
### `rails generate`
### `bin/rails generate`
The `bin/rails generate` command uses templates to create a whole lot of things. Running `bin/rails generate` by itself gives a list of available generators:
@ -176,7 +176,7 @@ Using generators will save you a large amount of time by writing **boilerplate c
Let's make our own controller with the controller generator. But what command should we use? Let's ask the generator:
INFO: All Rails console utilities have help text. As with most *nix utilities, you can try adding `--help` or `-h` to the end, for example `rails server --help`.
INFO: All Rails console utilities have help text. As with most *nix utilities, you can try adding `--help` or `-h` to the end, for example `bin/rails server --help`.
```bash
$ bin/rails generate controller
@ -240,7 +240,7 @@ Then the view, to display our message (in `app/views/greetings/hello.html.erb`):
<p><%= @message %></p>
```
Fire up your server using `rails server`.
Fire up your server using `bin/rails server`.
```bash
$ bin/rails server
@ -317,7 +317,7 @@ $ bin/rails generate scaffold HighScore game:string score:integer
The generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the `high_scores` table and fields), takes care of the route for the **resource**, and new tests for everything.
The migration requires that we **migrate**, that is, run some Ruby code (living in that `20130717151933_create_high_scores.rb`) to modify the schema of our database. Which database? The SQLite3 database that Rails will create for you when we run the `rails db:migrate` command. We'll talk more about that command below.
The migration requires that we **migrate**, that is, run some Ruby code (living in that `20130717151933_create_high_scores.rb`) to modify the schema of our database. Which database? The SQLite3 database that Rails will create for you when we run the `bin/rails db:migrate` command. We'll talk more about that command below.
```bash
$ bin/rails db:migrate
@ -343,11 +343,11 @@ $ bin/rails server
Go to your browser and open [http://localhost:3000/high_scores](http://localhost:3000/high_scores), now we can create new high scores (55,160 on Space Invaders!)
### `rails console`
### `bin/rails console`
The `console` command lets you interact with your Rails application from the command line. On the underside, `rails console` uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website.
The `console` command lets you interact with your Rails application from the command line. On the underside, `bin/rails console` uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website.
INFO: You can also use the alias "c" to invoke the console: `rails c`.
INFO: You can also use the alias "c" to invoke the console: `bin/rails c`.
You can specify the environment in which the `console` command should operate.
@ -355,7 +355,7 @@ You can specify the environment in which the `console` command should operate.
$ bin/rails console -e staging
```
If you wish to test out some code without changing any data, you can do that by invoking `rails console --sandbox`.
If you wish to test out some code without changing any data, you can do that by invoking `bin/rails console --sandbox`.
```bash
$ bin/rails console --sandbox
@ -366,7 +366,7 @@ irb(main):001:0>
#### The app and helper objects
Inside the `rails console` you have access to the `app` and `helper` instances.
Inside the `bin/rails console` you have access to the `app` and `helper` instances.
With the `app` method you can access named route helpers, as well as do requests.
@ -389,13 +389,13 @@ With the `helper` method it is possible to access Rails and your application's h
=> "my custom helper"
```
### `rails dbconsole`
### `bin/rails dbconsole`
`rails dbconsole` figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL (including MariaDB), PostgreSQL, and SQLite3.
`bin/rails dbconsole` figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL (including MariaDB), PostgreSQL, and SQLite3.
INFO: You can also use the alias "db" to invoke the dbconsole: `bin/rails db`.
### `rails runner`
### `bin/rails runner`
`runner` runs Ruby code in the context of Rails non-interactively. For instance:
@ -403,7 +403,7 @@ INFO: You can also use the alias "db" to invoke the dbconsole: `bin/rails db`.
$ bin/rails runner "Model.long_running_method"
```
INFO: You can also use the alias "r" to invoke the runner: `rails r`.
INFO: You can also use the alias "r" to invoke the runner: `bin/rails r`.
You can specify the environment in which the `runner` command should operate using the `-e` switch.
@ -417,11 +417,11 @@ You can even execute ruby code written in a file with runner.
$ bin/rails runner lib/code_to_be_run.rb
```
### `rails destroy`
### `bin/rails destroy`
Think of `destroy` as the opposite of `generate`. It'll figure out what generate did, and undo it.
INFO: You can also use the alias "d" to invoke the destroy command: `rails d`.
INFO: You can also use the alias "d" to invoke the destroy command: `bin/rails d`.
```bash
$ bin/rails generate model Oops
@ -442,9 +442,9 @@ $ bin/rails destroy model Oops
remove test/fixtures/oops.yml
```
### `rails about`
### `bin/rails about`
`rails about` gives information about version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version. It is useful when you need to ask for help, check if a security patch might affect you, or when you need some stats for an existing Rails installation.
`bin/rails about` gives information about version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version. It is useful when you need to ask for help, check if a security patch might affect you, or when you need some stats for an existing Rails installation.
```bash
$ bin/rails about
@ -461,21 +461,21 @@ Database adapter sqlite3
Database schema version 20180205173523
```
### `rails assets:`
### `bin/rails assets:`
You can precompile the assets in `app/assets` using `rails assets:precompile`, and remove older compiled assets using `rails assets:clean`. The `assets:clean` command allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
You can precompile the assets in `app/assets` using `bin/rails assets:precompile`, and remove older compiled assets using `bin/rails assets:clean`. The `assets:clean` command allows for rolling deploys that may still be linking to an old asset while the new assets are being built.
If you want to clear `public/assets` completely, you can use `rails assets:clobber`.
If you want to clear `public/assets` completely, you can use `bin/rails assets:clobber`.
### `rails db:`
### `bin/rails db:`
The most common commands of the `db:` rails namespace are `migrate` and `create`, and it will pay off to try out all of the migration rails commands (`up`, `down`, `redo`, `reset`). `rails db:version` is useful when troubleshooting, telling you the current version of the database.
The most common commands of the `db:` rails namespace are `migrate` and `create`, and it will pay off to try out all of the migration rails commands (`up`, `down`, `redo`, `reset`). `bin/rails db:version` is useful when troubleshooting, telling you the current version of the database.
More information about migrations can be found in the [Migrations](active_record_migrations.html) guide.
### `rails notes`
### `bin/rails notes`
`rails notes` searches through your code for comments beginning with a specific keyword. You can refer to `rails notes --help` for information about usage.
`bin/rails notes` searches through your code for comments beginning with a specific keyword. You can refer to `bin/rails notes --help` for information about usage.
By default, it will search in `app`, `config`, `db`, `lib`, and `test` directories for FIXME, OPTIMIZE, and TODO annotations in files with extension `.builder`, `.rb`, `.rake`, `.yml`, `.yaml`, `.ruby`, `.css`, `.js`, and `.erb`.
@ -514,7 +514,7 @@ config.annotations.register_tags("DEPRECATEME", "TESTME")
```
```bash
$ rails notes
$ bin/rails notes
app/controllers/admin/users_controller.rb:
* [ 20] [TODO] do A/B testing on this
* [ 42] [TESTME] this needs more functional tests
@ -577,17 +577,17 @@ vendor/tools.rb:
* [ 56] [TODO] Get rid of this dependency
```
### `rails routes`
### `bin/rails routes`
`rails routes` will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with.
`bin/rails routes` will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with.
### `rails test`
### `bin/rails test`
INFO: A good description of unit testing in Rails is given in [A Guide to Testing Rails Applications](testing.html)
Rails comes with a test framework called minitest. Rails owes its stability to the use of tests. The commands available in the `test:` namespace helps in running the different tests you will hopefully write.
### `rails tmp:`
### `bin/rails tmp:`
The `Rails.root/tmp` directory is, like the *nix /tmp directory, the holding place for temporary files like process id files and cached actions.

View file

@ -77,7 +77,7 @@ application. Accepts a valid day of week as a symbol (e.g. `:monday`).
* `config.consider_all_requests_local` is a flag. If `true` then any error will cause detailed debugging information to be dumped in the HTTP response, and the `Rails::Info` controller will show the application runtime context in `/rails/info/properties`. `true` by default in development and test environments, and `false` in production mode. For finer-grained control, set this to `false` and implement `show_detailed_exceptions?` in controllers to specify which requests should provide debugging information on errors.
* `config.console` allows you to set class that will be used as console you run `rails console`. It's best to run it in `console` block:
* `config.console` allows you to set class that will be used as console you run `bin/rails console`. It's best to run it in `console` block:
```ruby
console do
@ -439,7 +439,7 @@ All these configuration options are delegated to the `I18n` library.
Defaults to `false`.
* `config.active_record.use_schema_cache_dump` enables users to get schema cache information
from `db/schema_cache.yml` (generated by `rails db:schema:cache:dump`), instead of
from `db/schema_cache.yml` (generated by `bin/rails db:schema:cache:dump`), instead of
having to send a query to the database to get this information.
Defaults to `true`.
@ -1264,7 +1264,7 @@ By default Rails ships with three environments: "development", "test", and "prod
Imagine you have a server which mirrors the production environment but is only used for testing. Such a server is commonly called a "staging server". To define an environment called "staging" for this server, just create a file called `config/environments/staging.rb`. Please use the contents of any existing file in `config/environments` as a starting point and make the necessary changes from there.
That environment is no different than the default ones, start a server with `rails server -e staging`, a console with `rails console -e staging`, `Rails.env.staging?` works, etc.
That environment is no different than the default ones, start a server with `bin/rails server -e staging`, a console with `bin/rails console -e staging`, `Rails.env.staging?` works, etc.
### Deploy to a Subdirectory (relative URL root)

View file

@ -405,7 +405,7 @@ tells Rails to map requests to <http://localhost:3000/welcome/index> to the
welcome controller's index action. This was created earlier when you ran the
controller generator (`bin/rails generate controller Welcome index`).
Launch the web server again if you stopped it to generate the controller (`rails
Launch the web server again if you stopped it to generate the controller (`bin/rails
server`) and navigate to <http://localhost:3000> in your browser. You'll see the
"Hello, Rails!" message you put into `app/views/welcome/index.html.erb`,
indicating that this new route is indeed going to `WelcomeController`'s `index`

View file

@ -8,7 +8,7 @@ It is an extremely in-depth guide and recommended for advanced Rails developers.
After reading this guide, you will know:
* How to use `rails server`.
* How to use `bin/rails server`.
* The timeline of Rails' initialization sequence.
* Where different files are required by the boot sequence.
* How the Rails::Server interface is defined and used.
@ -32,41 +32,7 @@ Launch!
-------
Let's start to boot and initialize the app. A Rails application is usually
started by running `rails console` or `rails server`.
### `railties/exe/rails`
The `rails` in the command `rails server` is a ruby executable in your load
path. This executable contains the following lines:
```ruby
version = ">= 0"
load Gem.bin_path('railties', 'rails', version)
```
If you try out this command in a Rails console, you would see that this loads
`railties/exe/rails`. A part of the file `railties/exe/rails` has the
following code:
```ruby
require "rails/cli"
```
The file `railties/lib/rails/cli` in turn calls
`Rails::AppLoader.exec_app`.
### `railties/lib/rails/app_loader.rb`
The primary goal of the function `exec_app` is to execute your app's
`bin/rails`. If the current directory does not have a `bin/rails`, it will
navigate upwards until it finds a `bin/rails` executable. Thus one can invoke a
`rails` command from anywhere inside a rails application.
For `rails server` the equivalent of the following command is executed:
```bash
$ exec ruby bin/rails server
```
started by running `bin/rails console` or `bin/rails server`.
### `bin/rails`
@ -386,7 +352,7 @@ end
This method creates a trap for `INT` signals, so if you `CTRL-C` the server, it will exit the process.
As we can see from the code here, it will create the `tmp/cache`,
`tmp/pids`, and `tmp/sockets` directories. It then enables caching in development
if `rails server` is called with `--dev-caching`. Finally, it calls `wrapped_app` which is
if `bin/rails server` is called with `--dev-caching`. Finally, it calls `wrapped_app` which is
responsible for creating the Rack app, before creating and assigning an instance
of `ActiveSupport::Logger`.
@ -527,7 +493,7 @@ require_relative "config/environment"
### `config/environment.rb`
This file is the common file required by `config.ru` (`rails server`) and Passenger. This is where these two ways to run the server meet; everything before this point has been Rack and Rails setup.
This file is the common file required by `config.ru` (`bin/rails server`) and Passenger. This is where these two ways to run the server meet; everything before this point has been Rack and Rails setup.
This file begins with requiring `config/application.rb`:
@ -543,7 +509,7 @@ This file requires `config/boot.rb`:
require_relative "boot"
```
But only if it hasn't been required before, which would be the case in `rails server`
But only if it hasn't been required before, which would be the case in `bin/rails server`
but **wouldn't** be the case with Passenger.
Then the fun begins!

View file

@ -33,11 +33,11 @@ Rails on Rack
application. Any Rack compliant web server should be using
`Rails.application` object to serve a Rails application.
### `rails server`
### `bin/rails server`
`rails server` does the basic job of creating a `Rack::Server` object and starting the web server.
`bin/rails server` does the basic job of creating a `Rack::Server` object and starting the web server.
Here's how `rails server` creates an instance of `Rack::Server`
Here's how `bin/rails server` creates an instance of `Rack::Server`
```ruby
Rails::Server.new.tap do |server|
@ -60,7 +60,7 @@ end
### `rackup`
To use `rackup` instead of Rails' `rails server`, you can put the following inside `config.ru` of your Rails application's root directory:
To use `rackup` instead of Rails' `bin/rails server`, you can put the following inside `config.ru` of your Rails application's root directory:
```ruby
# Rails.root/config.ru

View file

@ -1230,7 +1230,7 @@ edit_user GET /users/:id/edit(.:format) users#edit
You can also use the `--expanded` option to turn on the expanded table formatting mode.
```
$ rails routes --expanded
$ bin/rails routes --expanded
--[ Route 1 ]----------------------------------------------------
Prefix | users

View file

@ -1175,7 +1175,7 @@ It is beyond the scope of this guide to inform you on how to secure your applica
Rails stores secrets in `config/credentials.yml.enc`, which is encrypted and hence cannot be edited directly. Rails uses `config/master.key` or alternatively looks for environment variable `ENV["RAILS_MASTER_KEY"]` to encrypt the credentials file. The credentials file can be stored in version control, as long as master key is kept safe.
To add new secret to credentials, first run `rails secret` to get a new secret. Then run `rails credentials:edit` to edit credentials, and add the secret. Running `credentials:edit` creates new credentials file and master key, if they did not already exist.
To add new secret to credentials, first run `bin/rails secret` to get a new secret. Then run `bin/rails credentials:edit` to edit credentials, and add the secret. Running `credentials:edit` creates new credentials file and master key, if they did not already exist.
By default, this file contains the application's
`secret_key_base`, but it could also be used to store other credentials such as access keys for external APIs.
@ -1198,7 +1198,7 @@ Rails.application.credentials.some_api_key! # => raises KeyError: :some_api_key
```
TIP: Learn more about credentials with `rails credentials:help`.
TIP: Learn more about credentials with `bin/rails credentials:help`.
WARNING: Keep your master key safe. Do not commit your master key.

View file

@ -437,11 +437,11 @@ Usage: rails test [options] [files or directories]
You can run a single test by appending a line number to a filename:
rails test test/models/user_test.rb:27
bin/rails test test/models/user_test.rb:27
You can run multiple files and directories at the same time:
rails test test/controllers test/integration/login_test.rb
bin/rails test test/controllers test/integration/login_test.rb
By default test failures and errors are reported inline during a run.
@ -489,7 +489,7 @@ parallelize your local test suite differently from your CI, so an environment va
to be able to easily change the number of workers a test run should use:
```bash
PARALLEL_WORKERS=15 rails test
PARALLEL_WORKERS=15 bin/rails test
```
When parallelizing tests, Active Record automatically handles creating a database and loading the schema into the database for each
@ -542,7 +542,7 @@ want to parallelize your local test suite differently from your CI, so an enviro
to be able to easily change the number of workers a test run should use:
```bash
PARALLEL_WORKERS=15 rails test
PARALLEL_WORKERS=15 bin/rails test
```
### Testing Parallel Transactions
@ -561,7 +561,7 @@ You can disable transactions in a test case class by setting
```ruby
class WorkerTest < ActiveSupport::TestCase
self.use_transactional_tests = false
test "parallel transactions" do
# start some threads that create transactions
end
@ -852,7 +852,7 @@ The test should see that there is an `h1` on the articles index page and pass.
Run the system tests.
```bash
rails test:system
bin/rails test:system
```
NOTE: By default, running `bin/rails test` won't run your system tests.

View file

@ -738,18 +738,16 @@ it.
`debugger` is not supported by Ruby 2.2 which is required by Rails 5. Use `byebug` instead.
### Use `rails` for running tasks and tests
### Use `bin/rails` for running tasks and tests
Rails 5 adds the ability to run tasks and tests through `bin/rails` instead of rake. Generally
these changes are in parallel with rake, but some were ported over altogether. As the `rails`
command already looks for and runs `bin/rails`, we recommend you to use the shorter `rails`
over `bin/rails`.
these changes are in parallel with rake, but some were ported over altogether.
To use the new test runner simply type `rails test`.
To use the new test runner simply type `bin/rails test`.
`rake dev:cache` is now `rails dev:cache`.
`rake dev:cache` is now `bin/rails dev:cache`.
Run `rails` inside your application's directory to see the list of commands available.
Run `bin/rails` inside your application's root directory to see the list of commands available.
### `ActionController::Parameters` No Longer Inherits from `HashWithIndifferentAccess`

View file

@ -79,7 +79,7 @@ module Rails
#
# For example, if the user invoke the controller generator as:
#
# rails generate controller Account --test-framework=test_unit
# bin/rails generate controller Account --test-framework=test_unit
#
# The controller generator will then try to invoke the following generators:
#
@ -134,11 +134,11 @@ module Rails
# All hooks come with switches for user interface. If you do not want
# to use any test framework, you can do:
#
# rails generate controller Account --skip-test-framework
# bin/rails generate controller Account --skip-test-framework
#
# Or similarly:
#
# rails generate controller Account --no-test-framework
# bin/rails generate controller Account --no-test-framework
#
# ==== Boolean hooks
#
@ -150,7 +150,7 @@ module Rails
#
# Then, if you want webrat to be invoked, just supply:
#
# rails generate controller Account --webrat
# bin/rails generate controller Account --webrat
#
# The hooks lookup is similar as above:
#

View file

@ -1,5 +1,5 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#

View file

@ -7,7 +7,7 @@ Description:
- No need to specify the number of iterations
Example:
`rails generate benchmark opt_compare`
`bin/rails generate benchmark opt_compare`
This will create:
script/benchmarks/opt_compare.rb
@ -16,4 +16,4 @@ Example:
`ruby script/benchmarks/opt_compare.rb`
You can specify different reports:
`rails generate benchmark opt_compare patch1 patch2 patch3`
`bin/rails generate benchmark opt_compare patch1 patch2 patch3`