Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encourage use of bin/rails over rails where needed #33203

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion actioncable/lib/rails/generators/channel/USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Description:

Example:
========
rails generate channel Chat speak
bin/rails generate channel Chat speak

creates a Chat channel class and CoffeeScript asset:
Channel: app/channels/chat_channel.rb
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
// You can generate new channels where WebSocket features live using
// the `bin/rails generate channel` command.
//
//= require action_cable
//= require_self
Expand Down
2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module ActionMailer
#
# To use Action Mailer, you need to create a mailer model.
#
# $ rails generate mailer Notifier
# $ bin/rails generate mailer Notifier
#
# The generated model inherits from <tt>ApplicationMailer</tt> which in turn
# inherits from <tt>ActionMailer::Base</tt>. A mailer model defines methods
Expand Down
2 changes: 1 addition & 1 deletion actionmailer/lib/rails/generators/mailer/USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description:

Example:
========
rails generate mailer Notifications signup forgot_password invoice
bin/rails generate mailer Notifications signup forgot_password invoice

creates a Notifications mailer class, views, and test:
Mailer: app/mailers/notifications_mailer.rb
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ module ActionDispatch
#
# == View a list of all your routes
#
# rails routes
# bin/rails routes
#
# Target a specific controller with <tt>-c</tt>, or grep routes
# using <tt>-g</tt>. Useful in conjunction with <tt>--expanded</tt>
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError #:nodoc:
# 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
Expand Down
10 changes: 5 additions & 5 deletions activerecord/lib/active_record/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def initialize(current: nil, stored: nil)
# The Rails package has several tools to help create and apply migrations.
#
# To generate a new migration, you can use
# rails generate migration MyNewMigration
# bin/rails generate migration MyNewMigration
#
# where MyNewMigration is the name of your migration. The generator will
# create an empty migration file <tt>timestamp_my_new_migration.rb</tt>
Expand All @@ -339,7 +339,7 @@ def initialize(current: nil, stored: nil)
#
# There is a special syntactic shortcut to generate migrations that add fields to a table.
#
# rails generate migration add_fieldname_to_tablename fieldname:string
# bin/rails generate migration add_fieldname_to_tablename fieldname:string
#
# This will generate the file <tt>timestamp_add_fieldname_to_tablename.rb</tt>, which will look like this:
# class AddFieldnameToTablename < ActiveRecord::Migration[5.0]
Expand All @@ -349,16 +349,16 @@ def initialize(current: nil, stored: nil)
# end
#
# To run migrations against the currently configured database, use
# <tt>rails db:migrate</tt>. This will update the database by running all of the
# <tt>bin/rails db:migrate</tt>. This will update the database by running all of the
# pending migrations, creating the <tt>schema_migrations</tt> table
# (see "About the schema_migrations table" section below) if missing. It will also
# invoke the db:schema:dump task, which will update your db/schema.rb file
# to match the structure of your database.
#
# To roll the database back to a previous migration version, use
# <tt>rails db:rollback VERSION=X</tt> where <tt>X</tt> is the version to which
# <tt>bin/rails db:rollback VERSION=X</tt> where <tt>X</tt> is the version to which
# you wish to downgrade. Alternatively, you can also use the STEP option if you
# wish to rollback last few migrations. <tt>rails db:rollback STEP=2</tt> will rollback
# wish to rollback last few migrations. <tt>bin/rails db:rollback STEP=2</tt> will rollback
# the latest two migrations.
#
# If any of the migrations throw an <tt>ActiveRecord::IrreversibleMigration</tt> exception,
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/railties/databases.rake
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,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` to update your database then try again.}
abort %{Run `bin/rails db:migrate` to update your database then try again.}
end
end

Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/tasks/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def load_schema_current(format = ActiveRecord::Base.schema_format, file = nil, e

def check_schema_file(filename)
unless File.exist?(filename)
message = %{#{filename} doesn't exist yet. Run `rails db:migrate` to create it, then try again.}.dup
message = %{#{filename} doesn't exist yet. Run `bin/rails db:migrate` to create it, then try again.}.dup
message << %{ If you do not intend to use a database, you should instead alter #{Rails.root}/config/application.rb to limit the frameworks that will be loaded.} if defined?(::Rails.root)
Kernel.abort message
end
Expand Down
2 changes: 1 addition & 1 deletion activestorage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ A key difference to how Active Storage works compared to other attachment soluti

## Installation

Run `rails active_storage:install` to copy over active_storage migrations.
Run `bin/rails active_storage:install` to copy over active_storage migrations.

## Examples

Expand Down
2 changes: 1 addition & 1 deletion activestorage/test/dummy/config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rails secret` to generate a secure secret key.
# You can use `bin/rails secret` to generate a secure secret key.

# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.
Expand Down
2 changes: 1 addition & 1 deletion guides/source/active_model_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ the Active Model API.
```

```bash
$ rails test
$ bin/rails test

Run options: --seed 14596

Expand Down
4 changes: 2 additions & 2 deletions guides/source/active_record_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ end
```

Rails keeps track of which files have been committed to the database and
provides rollback features. To actually create the table, you'd run `rails db:migrate`
and to roll it back, `rails db:rollback`.
provides rollback features. To actually create the table, you'd run `bin/rails db:migrate`
and to roll it back, `bin/rails db:rollback`.

Note that the above code is database-agnostic: it will run in MySQL,
PostgreSQL, Oracle, and others. You can learn more about migrations in the
Expand Down
26 changes: 13 additions & 13 deletions guides/source/active_record_migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ Running Migrations
Rails provides a set of bin/rails tasks to run certain sets of migrations.

The very first migration related bin/rails task you will use will probably be
`rails db:migrate`. In its most basic form it just runs the `change` or `up`
`bin/rails db:migrate`. In its most basic form it just runs the `change` or `up`
method for all the migrations that have not yet been run. If there are
no such migrations, it exits. It will run these migrations in order based
on the date of the migration.
Expand Down Expand Up @@ -788,17 +788,17 @@ version to migrate to.

### Setup the Database

The `rails db:setup` task will create the database, load the schema, and initialize
The `bin/rails db:setup` task will create the database, load the schema, and initialize
it with the seed data.

### Resetting the Database

The `rails db:reset` task will drop the database and set it up again. This is
functionally equivalent to `rails db:drop db:setup`.
The `bin/rails db:reset` task will drop the database and set it up again. This is
functionally equivalent to `bin/rails db:drop db:setup`.

NOTE: This is not the same as running all the migrations. It will only use the
contents of the current `db/schema.rb` or `db/structure.sql` file. If a migration can't be rolled back,
`rails db:reset` may not help you. To find out more about dumping the schema see
`bin/rails db:reset` may not help you. To find out more about dumping the schema see
[Schema Dumping and You](#schema-dumping-and-you) section.

### Running Specific Migrations
Expand Down Expand Up @@ -886,18 +886,18 @@ generates the following output
== CreateProducts: migrated (10.0054s) =======================================
```

If you want Active Record to not output anything, then running `rails db:migrate
VERBOSE=false` will suppress all output.
If you want Active Record to not output anything, then running `bin/rails
db:migrate VERBOSE=false` will suppress all output.

Changing Existing Migrations
----------------------------

Occasionally you will make a mistake when writing a migration. If you have
already run the migration, then you cannot just edit the migration and run the
migration again: Rails thinks it has already run the migration and so will do
nothing when you run `rails db:migrate`. You must rollback the migration (for
nothing when you run `bin/rails db:migrate`. You must rollback the migration (for
example with `bin/rails db:rollback`), edit your migration, and then run
`rails db:migrate` to run the corrected version.
`bin/rails db:migrate` to run the corrected version.

In general, editing existing migrations is not a good idea. You will be
creating extra work for yourself and your co-workers and cause major headaches
Expand All @@ -922,7 +922,7 @@ Rails generates `db/schema.rb` which attempts to capture the current state of
your database schema.

It tends to be faster and less error prone to create a new instance of your
application's database by loading the schema file via `rails db:schema:load`
application's database by loading the schema file via `bin/rails db:schema:load`
than it is to replay the entire migration history. Old migrations may fail to
apply correctly if those migrations use changing external dependencies or rely
on application code which evolves separately from your migrations.
Expand Down Expand Up @@ -976,7 +976,7 @@ using a tool specific to the database into `db/structure.sql`. For example, for
PostgreSQL, the `pg_dump` utility is used. For MySQL and MariaDB, this file will
contain the output of `SHOW CREATE TABLE` for the various tables.

To load the schema from `db/structure.sql`, run `rails db:structure:load`.
To load the schema from `db/structure.sql`, run `bin/rails db:structure:load`.
Loading this file is done by executing the SQL statements it contains. By
definition, this will create a perfect copy of the database's structure.

Expand All @@ -986,7 +986,7 @@ Because schema files are commonly used to create new databases, it is strongly
recommended that you check your schema file into source control.

Merge conflicts can occur in your schema file when two branches modify schema.
To resolve these conflicts run `rails db:migrate` to regenerate the schema file.
To resolve these conflicts run `bin/rails db:migrate` to regenerate the schema file.

Active Record and Referential Integrity
---------------------------------------
Expand Down Expand Up @@ -1032,7 +1032,7 @@ To add initial data after a database is created, Rails has a built-in
'seeds' feature that makes the process quick and easy. This is especially
useful when reloading the database frequently in development and test environments.
It's easy to get started with this feature: just fill up `db/seeds.rb` with some
Ruby code, and run `rails db:seed`:
Ruby code, and run `bin/rails db:seed`:

```ruby
5.times do |i|
Expand Down
4 changes: 2 additions & 2 deletions guides/source/active_storage_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ files.

Active Storage uses two tables in your application’s database named
`active_storage_blobs` and `active_storage_attachments`. After upgrading your
application to Rails 5.2, run `rails active_storage:install` to generate a
migration that creates these tables. Use `rails db:migrate` to run the
application to Rails 5.2, run `bin/rails active_storage:install` to generate a
migration that creates these tables. Use `bin/rails db:migrate` to run the
migration.

Declare Active Storage services in `config/storage.yml`. For each service your
Expand Down
2 changes: 1 addition & 1 deletion guides/source/api_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ building, and make sense in an API-only Rails application.
You can get a list of all middleware in your application via:

```bash
$ rails middleware
$ bin/rails middleware
```

### Using the Cache Middleware
Expand Down
4 changes: 2 additions & 2 deletions guides/source/association_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -2398,7 +2398,7 @@ specific behavior for each, and separated controllers too.
Rails makes this quite easy. First, let's generate the base Vehicle model:

```bash
$ rails generate model vehicle type:string color:string price:decimal{10.2}
$ bin/rails generate model vehicle type:string color:string price:decimal{10.2}
```

Did you note we are adding a "type" field? Since all models will be saved in a
Expand All @@ -2414,7 +2414,7 @@ table already exists).
For example, to generate the Car model:

```bash
$ rails generate model car --parent=Vehicle
$ bin/rails generate model car --parent=Vehicle
```

The generated model will look like this:
Expand Down
6 changes: 3 additions & 3 deletions guides/source/command_line.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ INFO: You can also use the alias "g" to invoke the generator command: `rails g`.

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

...
...
Expand Down Expand Up @@ -132,7 +132,7 @@ Description:
...

Example:
`rails generate controller CreditCards open debit credit close`
`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
Expand Down Expand Up @@ -196,7 +196,7 @@ Rails comes with a generator for data models too.
```bash
$ bin/rails generate model
Usage:
rails generate model NAME [field[:type][:index] field[:type][:index]] [options]
bin/rails generate model NAME [field[:type][:index] field[:type][:index]] [options]

...

Expand Down
8 changes: 4 additions & 4 deletions guides/source/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ application. Accepts a valid week day 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 `local_request?` 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
Expand Down Expand Up @@ -204,10 +204,10 @@ The full set of methods that can be used in this block are as follows:
* `javascripts` turns on the hook for JavaScript files in generators. Used in Rails for when the `scaffold` generator is run. Defaults to `true`.
* `javascript_engine` configures the engine to be used (for eg. coffee) when generating assets. Defaults to `:js`.
* `orm` defines which orm to use. Defaults to `false` and will use Active Record by default.
* `resource_controller` defines which generator to use for generating a controller when using `rails generate resource`. Defaults to `:controller`.
* `resource_controller` defines which generator to use for generating a controller when using `bin/rails generate resource`. Defaults to `:controller`.
* `resource_route` defines whether a resource route definition should be generated
or not. Defaults to `true`.
* `scaffold_controller` different from `resource_controller`, defines which generator to use for generating a _scaffolded_ controller when using `rails generate scaffold`. Defaults to `:scaffold_controller`.
* `scaffold_controller` different from `resource_controller`, defines which generator to use for generating a _scaffolded_ controller when using `bin/rails generate scaffold`. Defaults to `:scaffold_controller`.
* `stylesheets` turns on the hook for stylesheets in generators. Used in Rails for when the `scaffold` generator is run, but this hook can be used in other generates as well. Defaults to `true`.
* `stylesheet_engine` configures the stylesheet engine (for eg. sass) to be used when generating assets. Defaults to `:css`.
* `scaffold_stylesheet` creates `scaffold.css` when generating a scaffolded resource. Defaults to `true`.
Expand Down Expand Up @@ -1062,7 +1062,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)
Expand Down
4 changes: 2 additions & 2 deletions guides/source/engines.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,12 @@ later.

You can see what the engine has so far by running `bin/rails db:migrate` at the root
of our engine to run the migration generated by the scaffold generator, and then
running `rails server` in `test/dummy`. When you open
running `bin/rails server` in `test/dummy`. When you open
`http://localhost:3000/blorgh/articles` you will see the default scaffold that has
been generated. Click around! You've just generated your first engine's first
functions.

If you'd rather play around in the console, `rails console` will also work just
If you'd rather play around in the console, `bin/rails console` will also work just
like a Rails application. Remember: the `Article` model is namespaced, so to
reference it you must call it as `Blorgh::Article`.

Expand Down
6 changes: 3 additions & 3 deletions guides/source/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ After reading this guide, you will know:
First Contact
-------------

When you create an application using the `rails` command, you are in fact using a Rails generator. After that, you can get a list of all available generators by just invoking `rails generate`:
When you create an application using the `rails` command, you are in fact using a Rails generator. After that, you can get a list of all available generators by just invoking `bin/rails generate`:

```bash
$ rails new myapp
Expand Down Expand Up @@ -109,7 +109,7 @@ We can see that by invoking the description of this new generator (don't forget
```bash
$ bin/rails generate initializer --help
Usage:
rails generate initializer NAME [options]
bin/rails generate initializer NAME [options]
```

We can also see that our new generator has a class method called `source_root`. This method points to where our generator templates will be placed, if any, and by default it points to the created directory `lib/generators/initializer/templates`.
Expand Down Expand Up @@ -145,7 +145,7 @@ The methods that are available for generators are covered in the [final section]
Generators Lookup
-----------------

When you run `rails generate initializer core_extensions` Rails requires these files in turn until one is found:
When you run `bin/rails generate initializer core_extensions` Rails requires these files in turn until one is found:

```bash
rails/generators/initializer/initializer_generator.rb
Expand Down