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

remove reference to global rails command and replace with bin/rails

This commit is contained in:
Haroon Ahmed 2019-01-22 08:53:47 +00:00
parent 3eb1f1dd10
commit db1ae8cbb4
90 changed files with 336 additions and 338 deletions

View file

@ -68,7 +68,7 @@ and may also be used independently outside Rails.
3. Change directory to `myapp` and start the web server:
$ cd myapp
$ rails server
$ bin/rails server
Run with `--help` or `-h` for options.

View file

@ -5,7 +5,7 @@ Description:
Example:
========
rails generate channel Chat speak
bin/rails generate channel Chat speak
creates a Chat channel class, test and JavaScript asset:
Channel: app/channels/chat_channel.rb

View file

@ -1,5 +1,5 @@
// 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.
import { createConsumer } from "@rails/actioncable"

View file

@ -24,7 +24,7 @@ module ActionMailbox
# 1. Give Action Mailbox your {Mailgun API key}[https://help.mailgun.com/hc/en-us/articles/203380100-Where-can-I-find-my-API-key-and-SMTP-credentials-]
# so it can authenticate requests to the Mailgun ingress.
#
# Use <tt>rails credentials:edit</tt> to add your API key to your application's encrypted credentials under
# Use <tt>bin/rails credentials:edit</tt> to add your API key to your application's encrypted credentials under
# +action_mailbox.mailgun_api_key+, where Action Mailbox will automatically find it:
#
# action_mailbox:

View file

@ -27,7 +27,7 @@ module ActionMailbox
#
# 2. Generate a strong password that Action Mailbox can use to authenticate requests to the Postmark ingress.
#
# Use <tt>rails credentials:edit</tt> to add the password to your application's encrypted credentials under
# Use <tt>bin/rails credentials:edit</tt> to add the password to your application's encrypted credentials under
# +action_mailbox.ingress_password+, where Action Mailbox will automatically find it:
#
# action_mailbox:

View file

@ -27,7 +27,7 @@ module ActionMailbox
#
# 2. Generate a strong password that Action Mailbox can use to authenticate requests to the ingress.
#
# Use <tt>rails credentials:edit</tt> to add the password to your application's encrypted credentials under
# Use <tt>bin/rails credentials:edit</tt> to add the password to your application's encrypted credentials under
# +action_mailbox.ingress_password+, where Action Mailbox will automatically find it:
#
# action_mailbox:

View file

@ -27,7 +27,7 @@ module ActionMailbox
#
# 2. Generate a strong password that Action Mailbox can use to authenticate requests to the SendGrid ingress.
#
# Use <tt>rails credentials:edit</tt> to add the password to your application's encrypted credentials under
# Use <tt>bin/rails credentials:edit</tt> to add the password to your application's encrypted credentials under
# +action_mailbox.ingress_password+, where Action Mailbox will automatically find it:
#
# action_mailbox:

View file

@ -5,7 +5,7 @@ Description:
Example:
========
rails generate mailbox inbox
bin/rails generate mailbox inbox
creates an InboxMailbox class and test:
Mailbox: app/mailboxes/inbox_mailbox.rb

View file

@ -15,7 +15,7 @@ Rails.application.configure do
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
# Run bin/rails dev:cache to toggle caching.
if Rails.root.join('tmp', 'caching-dev.txt').exist?
config.action_controller.perform_caching = true

View file

@ -30,5 +30,5 @@ environment ENV.fetch("RAILS_ENV", "development")
#
# preload_app!
# Allow puma to be restarted by `rails restart` command.
# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart

View file

@ -6,7 +6,7 @@ local:
service: Disk
root: <%= Rails.root.join("storage") %>
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
# service: S3
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
@ -21,7 +21,7 @@ local:
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
# bucket: your_own_bucket
# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft:
# service: AzureStorage
# path: your_azure_storage_path

View file

@ -2,8 +2,8 @@
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.

View file

@ -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

View file

@ -8,10 +8,9 @@ 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
Views: app/views/notifications_mailer/signup.text.erb [...]
Test: test/mailers/notifications_mailer_test.rb

View file

@ -87,7 +87,7 @@ module ActionDispatch
end
end
# Needed for `rails routes`. Picks up succinctly defined requirements
# Needed for `bin/rails routes`. Picks up succinctly defined requirements
# for a route, for example route
#
# get 'photo/:id', :controller => 'photos', :action => 'show',

View file

@ -11,10 +11,10 @@
<h2>
<%= h @exception.message %>
<% if defined?(ActiveStorage) && @exception.message.match?(%r{#{ActiveStorage::Blob.table_name}|#{ActiveStorage::Attachment.table_name}}) %>
<br />To resolve this issue run: rails active_storage:install
<br />To resolve this issue run: bin/rails active_storage:install
<% end %>
<% if defined?(ActionMailbox) && @exception.message.match?(%r{#{ActionMailbox::InboundEmail.table_name}}) %>
<br />To resolve this issue run: rails action_mailbox:install
<br />To resolve this issue run: bin/rails action_mailbox:install
<% end %>
</h2>

View file

@ -5,9 +5,9 @@
<%= @exception.message %>
<% if defined?(ActiveStorage) && @exception.message.match?(%r{#{ActiveStorage::Blob.table_name}|#{ActiveStorage::Attachment.table_name}}) %>
To resolve this issue run: rails active_storage:install
To resolve this issue run: bin/rails active_storage:install
<% if defined?(ActionMailbox) && @exception.message.match?(%r{#{ActionMailbox::InboundEmail.table_name}}) %>
To resolve this issue run: rails action_mailbox:install
To resolve this issue run: bin/rails action_mailbox:install
<% end %>
<%= render template: "rescues/_source" %>

View file

@ -53,7 +53,7 @@ module ActionDispatch
##
# This class is just used for displaying route information when someone
# executes `rails routes` or looks at the RoutingError page.
# executes `bin/rails routes` or looks at the RoutingError page.
# People should not use this class.
class RoutesInspector # :nodoc:
def initialize(routes)

View file

@ -15,7 +15,7 @@ Rails.application.configure do
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
# Run bin/rails dev:cache to toggle caching.
if Rails.root.join('tmp', 'caching-dev.txt').exist?
config.action_controller.perform_caching = true

View file

@ -30,5 +30,5 @@ environment ENV.fetch("RAILS_ENV") { "development" }
#
# preload_app!
# Allow puma to be restarted by `rails restart` command.
# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart

View file

@ -6,7 +6,7 @@ local:
service: Disk
root: <%= Rails.root.join("storage") %>
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
# service: S3
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
@ -21,7 +21,7 @@ local:
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
# bucket: your_own_bucket
# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft:
# service: AzureStorage
# path: your_azure_storage_path

View file

@ -98,7 +98,7 @@ module ActionView
# have SSL certificates for each of the asset hosts this technique allows you
# to avoid warnings in the client about mixed media.
# Note that the +request+ parameter might not be supplied, e.g. when the assets
# are precompiled with the command `rails assets:precompile`. Make sure to use a
# are precompiled with the command `bin/rails assets:precompile`. Make sure to use a
# +Proc+ instead of a lambda, since a +Proc+ allows missing parameters and sets them
# to +nil+.
#

View file

@ -181,7 +181,7 @@ module ActiveRecord
# end
# end
#
# If you preload your test database with all fixture data (probably by running `rails db:fixtures:load`)
# If you preload your test database with all fixture data (probably by running `bin/rails db:fixtures:load`)
# and use transactional tests, then you may omit all fixtures declarations in your test cases since
# all the data's already there and every case rolls back its changes.
#

View file

@ -138,9 +138,9 @@ module ActiveRecord
def initialize(message = nil)
if !message && defined?(Rails.env)
super("Migrations are pending. To resolve this issue, run:\n\n rails db:migrate RAILS_ENV=#{::Rails.env}")
super("Migrations are pending. To resolve this issue, run:\n\n bin/rails db:migrate RAILS_ENV=#{::Rails.env}")
elsif !message
super("Migrations are pending. To resolve this issue, run:\n\n rails db:migrate")
super("Migrations are pending. To resolve this issue, run:\n\n bin/rails db:migrate")
else
super
end
@ -158,7 +158,7 @@ module ActiveRecord
class NoEnvironmentInSchemaError < MigrationError #:nodoc:
def initialize
msg = "Environment data not found in the schema. To resolve this issue, run: \n\n rails db:environment:set"
msg = "Environment data not found in the schema. To resolve this issue, run: \n\n bin/rails db:environment:set"
if defined?(Rails.env)
super("#{msg} RAILS_ENV=#{::Rails.env}")
else
@ -181,7 +181,7 @@ module ActiveRecord
msg = +"You are attempting to modify a database that was last run in `#{ stored }` environment.\n"
msg << "You are running in `#{ current }` environment. "
msg << "If you are sure you want to continue, first set the environment using:\n\n"
msg << " rails db:environment:set"
msg << " bin/rails db:environment:set"
if defined?(Rails.env)
super("#{msg} RAILS_ENV=#{::Rails.env}\n\n")
else
@ -338,7 +338,7 @@ module ActiveRecord
# 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>
@ -347,7 +347,7 @@ module ActiveRecord
#
# 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]
@ -357,16 +357,16 @@ module ActiveRecord
# 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 command, 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,

View file

@ -266,7 +266,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
ensure
ActiveRecord::Base.establish_connection(ActiveRecord::Tasks::DatabaseTasks.env.to_sym)

View file

@ -72,8 +72,8 @@ module ActiveRecord
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.

View file

@ -428,7 +428,7 @@ module ActiveRecord
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.}
message = +%{#{filename} doesn't exist yet. Run `bin/rails db:migrate` to create it, then try again.}
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

View file

@ -16,7 +16,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.
NOTE: If the task cannot be found, verify that `require "active_storage/engine"` is present in `config/application.rb`.

View file

@ -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.
@ -25,7 +25,7 @@ test:
# Do not keep production secrets in the unencrypted secrets file.
# Instead, either read values from the environment.
# Or, use `rails secrets:setup` to configure encrypted secrets
# Or, use `bin/rails secrets:setup` to configure encrypted secrets
# and move the `production:` environment over there.
production:

View file

@ -146,12 +146,12 @@ Railties
* Add an alias `d` for `destroy`. This works for engines too.
* Attributes on scaffold and model generators default to string. This allows the following: `rails g scaffold Post title body:text author`
* Attributes on scaffold and model generators default to string. This allows the following: `bin/rails g scaffold Post title body:text author`
* Allow scaffold/model/migration generators to accept "index" and "uniq" modifiers. For example,
```ruby
rails g scaffold Post title:string:index author:uniq price:decimal{7,2}
bin/rails g scaffold Post title:string:index author:uniq price:decimal{7,2}
```
will create indexes for `title` and `author` with the latter being a unique index. Some types such as decimal accept custom options. In the example, `price` will be a decimal column with precision and scale set to 7 and 2 respectively.

View file

@ -187,7 +187,7 @@ established using the following JavaScript, which is generated by default by Rai
```js
// app/javascript/channels/consumer.js
// 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.
import { createConsumer } from "@rails/actioncable"

View file

@ -395,7 +395,7 @@ You can also pass a `:domain` key and specify the domain name for the cookie:
Rails.application.config.session_store :cookie_store, key: '_your_app_session', domain: ".example.com"
```
Rails sets up (for the CookieStore) a secret key used for signing the session data in `config/credentials.yml.enc`. This can be changed with `rails credentials:edit`.
Rails sets up (for the CookieStore) a secret key used for signing the session data in `config/credentials.yml.enc`. This can be changed with `bin/rails credentials:edit`.
```yaml
# aws:

View file

@ -37,8 +37,8 @@ with the rest of your domain model.
Install migrations needed for `InboundEmail` and ensure Active Storage is set up:
```bash
$ rails action_mailbox:install
$ rails db:migrate
$ bin/rails action_mailbox:install
$ bin/rails db:migrate
```
## Configuration
@ -54,7 +54,7 @@ config.action_mailbox.ingress = :relay
Generate a strong password that Action Mailbox can use to authenticate requests to the relay ingress.
Use `rails credentials:edit` to add the password to your application's encrypted credentials under
Use `bin/rails credentials:edit` to add the password to your application's encrypted credentials under
`action_mailbox.ingress_password`, where Action Mailbox will automatically find it:
```yaml
@ -79,7 +79,7 @@ Give Action Mailbox your
[Mailgun API key](https://help.mailgun.com/hc/en-us/articles/203380100-Where-can-I-find-my-API-key-and-SMTP-credentials)
so it can authenticate requests to the Mailgun ingress.
Use `rails credentials:edit` to add your API key to your application's
Use `bin/rails credentials:edit` to add your API key to your application's
encrypted credentials under `action_mailbox.mailgun_api_key`,
where Action Mailbox will automatically find it:
@ -108,7 +108,7 @@ fully-qualified URL `https://example.com/rails/action_mailbox/mailgun/inbound_em
Give Action Mailbox your Mandrill API key so it can authenticate requests to
the Mandrill ingress.
Use `rails credentials:edit` to add your API key to your application's
Use `bin/rails credentials:edit` to add your API key to your application's
encrypted credentials under `action_mailbox.mandrill_api_key`,
where Action Mailbox will automatically find it:
@ -143,7 +143,7 @@ config.action_mailbox.ingress = :relay
Generate a strong password that Action Mailbox can use to authenticate requests to the relay ingress.
Use `rails credentials:edit` to add the password to your application's encrypted credentials under
Use `bin/rails credentials:edit` to add the password to your application's encrypted credentials under
`action_mailbox.ingress_password`, where Action Mailbox will automatically find it:
```yaml
@ -175,7 +175,7 @@ config.action_mailbox.ingress = :postmark
Generate a strong password that Action Mailbox can use to authenticate
requests to the Postmark ingress.
Use `rails credentials:edit` to add the password to your application's
Use `bin/rails credentials:edit` to add the password to your application's
encrypted credentials under `action_mailbox.ingress_password`,
where Action Mailbox will automatically find it:
@ -210,7 +210,7 @@ config.action_mailbox.ingress = :relay
Generate a strong password that Action Mailbox can use to authenticate requests to the relay ingress.
Use `rails credentials:edit` to add the password to your application's encrypted credentials under
Use `bin/rails credentials:edit` to add the password to your application's encrypted credentials under
`action_mailbox.ingress_password`, where Action Mailbox will automatically find it:
```yaml
@ -241,7 +241,7 @@ config.action_mailbox.ingress = :sendgrid
Generate a strong password that Action Mailbox can use to authenticate
requests to the SendGrid ingress.
Use `rails credentials:edit` to add the password to your application's
Use `bin/rails credentials:edit` to add the password to your application's
encrypted credentials under `action_mailbox.ingress_password`,
where Action Mailbox will automatically find it:

View file

@ -44,7 +44,7 @@ views.
#### Create the Mailer
```bash
$ rails generate mailer UserMailer
$ bin/rails generate mailer UserMailer
create app/mailers/user_mailer.rb
create app/mailers/application_mailer.rb
invoke erb
@ -173,8 +173,8 @@ Setting this up is simple.
First, let's create a simple `User` scaffold:
```bash
$ rails generate scaffold user name email login
$ rails db:migrate
$ bin/rails generate scaffold user name email login
$ bin/rails db:migrate
```
Now that we have a user model to play with, we will just edit the

View file

@ -45,7 +45,7 @@ happens after every keystroke, and avoids the need to use execCommand at all.
## Installation
Run `rails action_text:install` to add the Yarn package and copy over the necessary migration. Also, you need to set up Active Storage for embedded images and other attachments. Please refer to the [Active Storage Overview](active_storage_overview.html) guide.
Run `bin/rails action_text:install` to add the Yarn package and copy over the necessary migration. Also, you need to set up Active Storage for embedded images and other attachments. Please refer to the [Active Storage Overview](active_storage_overview.html) guide.
After the installation is complete, a Rails app using Webpacker should have the following changes:

View file

@ -29,7 +29,7 @@ For each controller there is an associated directory in the `app/views` director
Let's take a look at what Rails does by default when creating a new resource using the scaffold generator:
```bash
$ rails generate scaffold article
$ bin/rails generate scaffold article
[...]
invoke scaffold_controller
create app/controllers/articles_controller.rb

View file

@ -50,7 +50,7 @@ Active Job provides a Rails generator to create jobs. The following will create
job in `app/jobs` (with an attached test case under `test/jobs`):
```bash
$ rails generate job guests_cleanup
$ bin/rails generate job guests_cleanup
invoke test_unit
create test/jobs/guests_cleanup_job_test.rb
create app/jobs/guests_cleanup_job.rb
@ -59,7 +59,7 @@ create app/jobs/guests_cleanup_job.rb
You can also create a job that will run on a specific queue:
```bash
$ rails generate job guests_cleanup --queue urgent
$ bin/rails generate job guests_cleanup --queue urgent
```
If you don't want to use a generator, you could create your own file inside of

View file

@ -437,7 +437,7 @@ the Active Model API.
```
```bash
$ rails test
$ bin/rails test
Run options: --seed 14596

View file

@ -384,8 +384,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

View file

@ -122,7 +122,7 @@ Of course, calculating timestamps is no fun, so Active Record provides a
generator to handle making it for you:
```bash
$ rails generate migration AddPartNumberToProducts
$ bin/rails generate migration AddPartNumberToProducts
```
This will create an appropriately named empty migration:
@ -144,7 +144,7 @@ types then a migration containing the appropriate `add_column` and
`remove_column` statements will be created.
```bash
$ rails generate migration AddPartNumberToProducts part_number:string
$ bin/rails generate migration AddPartNumberToProducts part_number:string
```
will generate
@ -160,7 +160,7 @@ end
If you'd like to add an index on the new column, you can do that as well:
```bash
$ rails generate migration AddPartNumberToProducts part_number:string:index
$ bin/rails generate migration AddPartNumberToProducts part_number:string:index
```
will generate
@ -178,7 +178,7 @@ end
Similarly, you can generate a migration to remove a column from the command line:
```bash
$ rails generate migration RemovePartNumberFromProducts part_number:string
$ bin/rails generate migration RemovePartNumberFromProducts part_number:string
```
generates
@ -194,7 +194,7 @@ end
You are not limited to one magically generated column. For example:
```bash
$ rails generate migration AddDetailsToProducts part_number:string price:decimal
$ bin/rails generate migration AddDetailsToProducts part_number:string price:decimal
```
generates
@ -213,7 +213,7 @@ followed by a list of column names and types then a migration creating the table
XXX with the columns listed will be generated. For example:
```bash
$ rails generate migration CreateProducts name:string part_number:string
$ bin/rails generate migration CreateProducts name:string part_number:string
```
generates
@ -239,7 +239,7 @@ Also, the generator accepts column type as `references` (also available as
`belongs_to`). For instance:
```bash
$ rails generate migration AddUserRefToProducts user:references
$ bin/rails generate migration AddUserRefToProducts user:references
```
generates
@ -258,7 +258,7 @@ For more `add_reference` options, visit the [API documentation](https://api.ruby
There is also a generator which will produce join tables if `JoinTable` is part of the name:
```bash
$ rails generate migration CreateJoinTableCustomerProduct customer product
$ bin/rails generate migration CreateJoinTableCustomerProduct customer product
```
will produce the following migration:
@ -282,7 +282,7 @@ relevant table. If you tell Rails what columns you want, then statements for
adding these columns will also be created. For example, running:
```bash
$ rails generate model Product name:string description:text
$ bin/rails generate model Product name:string description:text
```
will create a migration that looks like this
@ -310,7 +310,7 @@ the command line. They are enclosed by curly braces and follow the field type:
For instance, running:
```bash
$ rails generate migration AddDetailsToProducts 'price:decimal{5,2}' supplier:references{polymorphic}
$ bin/rails generate migration AddDetailsToProducts 'price:decimal{5,2}' supplier:references{polymorphic}
```
will produce a migration that looks like this
@ -735,7 +735,7 @@ Running Migrations
Rails provides a set of rails commands to run certain sets of migrations.
The very first migration related rails command 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.
@ -749,7 +749,7 @@ is the numerical prefix on the migration's filename. For example, to migrate
to version 20080906120000 run:
```bash
$ rails db:migrate VERSION=20080906120000
$ bin/rails db:migrate VERSION=20080906120000
```
If version 20080906120000 is greater than the current version (i.e., it is
@ -766,7 +766,7 @@ mistake in it and wish to correct it. Rather than tracking down the version
number associated with the previous migration you can run:
```bash
$ rails db:rollback
$ bin/rails db:rollback
```
This will rollback the latest migration, either by reverting the `change`
@ -774,7 +774,7 @@ method or by running the `down` method. If you need to undo
several migrations you can provide a `STEP` parameter:
```bash
$ rails db:rollback STEP=3
$ bin/rails db:rollback STEP=3
```
will revert the last 3 migrations.
@ -784,7 +784,7 @@ back up again. As with the `db:rollback` command, you can use the `STEP` paramet
if you need to go more than one version back, for example:
```bash
$ rails db:migrate:redo STEP=3
$ bin/rails db:migrate:redo STEP=3
```
Neither of these rails commands do anything you could not do with `db:migrate`. They
@ -793,17 +793,17 @@ version to migrate to.
### Setup the Database
The `rails db:setup` command will create the database, load the schema, and initialize
The `bin/rails db:setup` command will create the database, load the schema, and initialize
it with the seed data.
### Resetting the Database
The `rails db:reset` command will drop the database and set it up again. This is
functionally equivalent to `rails db:drop db:setup`.
The `bin/rails db:reset` command 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
@ -814,7 +814,7 @@ the corresponding migration will have its `change`, `up` or `down` method
invoked, for example:
```bash
$ rails db:migrate:up VERSION=20080906120000
$ bin/rails db:migrate:up VERSION=20080906120000
```
will run the 20080906120000 migration by running the `change` method (or the
@ -824,13 +824,13 @@ Active Record believes that it has already been run.
### Running Migrations in Different Environments
By default running `rails db:migrate` will run in the `development` environment.
By default running `bin/rails db:migrate` will run in the `development` environment.
To run migrations against another environment you can specify it using the
`RAILS_ENV` environment variable while running the command. For example to run
migrations against the `test` environment you could run:
```bash
$ rails db:migrate RAILS_ENV=test
$ bin/rails db:migrate RAILS_ENV=test
```
### Changing the Output of Running Migrations
@ -891,7 +891,7 @@ generates the following output
== CreateProducts: migrated (10.0054s) =======================================
```
If you want Active Record to not output anything, then running `rails db:migrate
If you want Active Record to not output anything, then running `bin/rails db:migrate
VERBOSE=false` will suppress all output.
Changing Existing Migrations
@ -900,9 +900,9 @@ 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
example with `rails db:rollback`), edit your migration, and then run
`rails db:migrate` to run the corrected version.
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
`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
@ -927,7 +927,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](#old-migrations) may fail to apply correctly if those
migrations use changing external dependencies or rely on application code which
@ -982,7 +982,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.
@ -992,7 +992,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
---------------------------------------
@ -1038,7 +1038,7 @@ To add initial data after a database is created, Rails has a built-in
'seeds' feature that speeds up the process. This is especially
useful when reloading the database frequently in development and test environments.
To get started with this feature, 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|
@ -1057,12 +1057,12 @@ database and is the authoritative source for rebuilding that database. This
makes it possible to delete old migration files.
When you delete migration files in the `db/migrate/` directory, any environment
where `rails db:migrate` was run when those files still existed will hold a reference
where `bin/rails db:migrate` was run when those files still existed will hold a reference
to the migration timestamp specific to them inside an internal Rails database
table named `schema_migrations`. This table is used to keep track of whether
migrations have been executed in a specific environment.
If you run the `rails db:migrate:status` command, which displays the status
If you run the `bin/rails db:migrate:status` command, which displays the status
(up or down) of each migration, you should see `********** NO FILE **********`
displayed next to any deleted migration file which was once executed on a
specific environment but can no longer be found in the `db/migrate/` directory.

View file

@ -167,7 +167,7 @@ For example the `animals` database would look in the `db/animals_migrate` direct
so that the file is generated in the correct directory. The command can be run like so:
```bash
$ rails generate migration CreateDogs name:string --database animals
$ bin/rails generate migration CreateDogs name:string --database animals
```
## Activating automatic connection switching

View file

@ -276,7 +276,7 @@ end
NOTE: ENUM values can't be dropped currently. You can read why [here](https://www.postgresql.org/message-id/29F36C7C98AB09499B1A209D48EAA615B7653DBC8A@mail2a.alliedtesting.com).
Hint: to show all the values of the all enums you have, you should call this query in `rails db` or `psql` console:
Hint: to show all the values of the all enums you have, you should call this query in `bin/rails db` or `psql` console:
```sql
SELECT n.nspname AS enum_schema,

View file

@ -83,10 +83,10 @@ class Person < ApplicationRecord
end
```
We can see how it works by looking at some `rails console` output:
We can see how it works by looking at some `bin/rails console` output:
```ruby
$ rails console
$ bin/rails console
>> p = Person.new(name: "John Doe")
=> #<Person id: nil, name: "John Doe", created_at: nil, updated_at: nil>
>> p.new_record?

View file

@ -38,8 +38,8 @@ files.
Active Storage uses two tables in your applications database named
`active_storage_blobs` and `active_storage_attachments`. After creating a new
application (or 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 migration.
`bin/rails active_storage:install` to generate a migration that creates these
tables. Use `bin/rails db:migrate` to run the migration.
WARNING: `active_storage_attachments` is a polymorphic join table that stores your model's class name. If your model's class name changes, you will need to run a migration on this table to update the underlying `record_type` to your model's new class name.

View file

@ -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
@ -391,7 +391,7 @@ Other plugins may add additional modules. You can get a list of all modules
included into `ActionController::API` in the rails console:
```bash
$ rails c
$ bin/rails c
>> ActionController::API.ancestors - ActionController::Metal.ancestors
=> [ActionController::API,
ActiveRecord::Railties::ControllerRuntime,

View file

@ -2462,7 +2462,7 @@ specific behavior for each, and separated controllers too.
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
@ -2478,7 +2478,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:

View file

@ -412,7 +412,7 @@ Rails is always able to autoload provided its environment is in place. For
example the `runner` command autoloads:
```bash
$ rails runner 'p User.column_names'
$ bin/rails runner 'p User.column_names'
["id", "email", "created_at", "updated_at"]
```
@ -486,7 +486,7 @@ The value of `autoload_paths` can be inspected. In a just-generated application
it is (edited):
```bash
$ rails runner 'puts ActiveSupport::Dependencies.autoload_paths'
$ bin/rails runner 'puts ActiveSupport::Dependencies.autoload_paths'
.../app/assets
.../app/channels
.../app/controllers
@ -1226,7 +1226,7 @@ been loaded but `app/models/hotel/image.rb` hasn't, Ruby does not find `Image`
in `Hotel`, but it does in `Object`:
```bash
$ rails runner 'Image; p Hotel::Image' 2>/dev/null
$ bin/rails runner 'Image; p Hotel::Image' 2>/dev/null
Image # NOT Hotel::Image!
```

View file

@ -670,9 +670,9 @@ in development mode. Rails provides the rails command `dev:cache` to
easily toggle caching on/off.
```bash
$ rails dev:cache
$ bin/rails dev:cache
Development mode is now being cached.
$ rails dev:cache
$ bin/rails dev:cache
Development mode is no longer being cached.
```

View file

@ -19,14 +19,14 @@ Command Line Basics
There are a few commands that are absolutely critical to your everyday usage of Rails. In the order of how much you'll probably use them are:
* `rails console`
* `rails server`
* `rails test`
* `rails generate`
* `rails db:migrate`
* `rails db:create`
* `rails routes`
* `rails dbconsole`
* `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`
You can get a list of rails commands available to you, which will often depend on your current directory, by typing `rails --help`. Each command has a description, and should help you find the thing you need.
@ -122,7 +122,7 @@ With no further work, `rails server` will run our new shiny Rails app:
```bash
$ cd commandsapp
$ rails server
$ bin/rails server
=> Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `rails server --help` for more startup options
@ -141,19 +141,19 @@ INFO: You can also use the alias "s" to start the server: `rails s`.
The server can be run on a different port using the `-p` option. The default development environment can be changed using `-e`.
```bash
$ rails server -e production -p 4000
$ 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`
The `rails generate` command uses templates to create a whole lot of things. Running `rails generate` by itself gives a list of available generators:
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:
INFO: You can also use the alias "g" to invoke the generator command: `rails g`.
INFO: You can also use the alias "g" to invoke the generator command: `bin/rails g`.
```bash
$ rails generate
$ bin/rails generate
Usage: rails generate GENERATOR [args] [options]
...
@ -179,8 +179,8 @@ Let's make our own controller with the controller generator. But what command sh
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`.
```bash
$ rails generate controller
Usage: rails generate controller NAME [action action] [options]
$ bin/rails generate controller
Usage: bin/rails generate controller NAME [action action] [options]
...
...
@ -193,7 +193,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
@ -205,7 +205,7 @@ Example:
The controller generator is expecting parameters in the form of `generate controller ControllerName action1 action2`. Let's make a `Greetings` controller with an action of **hello**, which will say something nice to us.
```bash
$ rails generate controller Greetings hello
$ bin/rails generate controller Greetings hello
create app/controllers/greetings_controller.rb
route get 'greetings/hello'
invoke erb
@ -243,7 +243,7 @@ Then the view, to display our message (in `app/views/greetings/hello.html.erb`):
Fire up your server using `rails server`.
```bash
$ rails server
$ bin/rails server
=> Booting Puma...
```
@ -254,9 +254,9 @@ INFO: With a normal, plain-old Rails application, your URLs will generally follo
Rails comes with a generator for data models too.
```bash
$ rails generate model
$ 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]
...
@ -280,7 +280,7 @@ But instead of generating a model directly (which we'll be doing later), let's s
We will set up a simple resource called "HighScore" that will keep track of our highest score on video games we play.
```bash
$ rails generate scaffold HighScore game:string score:integer
$ 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
@ -320,7 +320,7 @@ The generator checks that there exist the directories for models, controllers, h
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.
```bash
$ rails db:migrate
$ bin/rails db:migrate
== CreateHighScores: migrating ===============================================
-- create_table(:high_scores)
-> 0.0017s
@ -338,7 +338,7 @@ look at unit testing.
Let's see the interface Rails created for us.
```bash
$ rails server
$ 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!)
@ -352,13 +352,13 @@ INFO: You can also use the alias "c" to invoke the console: `rails c`.
You can specify the environment in which the `console` command should operate.
```bash
$ rails console -e staging
$ 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`.
```bash
$ rails console --sandbox
$ bin/rails console --sandbox
Loading development environment in sandbox (Rails 5.1.0)
Any modifications you make will be rolled back on exit
irb(main):001:0>
@ -393,14 +393,14 @@ With the `helper` method it is possible to access Rails and your application's h
`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: `rails db`.
INFO: You can also use the alias "db" to invoke the dbconsole: `bin/rails db`.
### `rails runner`
`runner` runs Ruby code in the context of Rails non-interactively. For instance:
```bash
$ rails runner "Model.long_running_method"
$ bin/rails runner "Model.long_running_method"
```
INFO: You can also use the alias "r" to invoke the runner: `rails r`.
@ -408,13 +408,13 @@ INFO: You can also use the alias "r" to invoke the runner: `rails r`.
You can specify the environment in which the `runner` command should operate using the `-e` switch.
```bash
$ rails runner -e staging "Model.long_running_method"
$ bin/rails runner -e staging "Model.long_running_method"
```
You can even execute ruby code written in a file with runner.
```bash
$ rails runner lib/code_to_be_run.rb
$ bin/rails runner lib/code_to_be_run.rb
```
### `rails destroy`
@ -424,7 +424,7 @@ Think of `destroy` as the opposite of `generate`. It'll figure out what generate
INFO: You can also use the alias "d" to invoke the destroy command: `rails d`.
```bash
$ rails generate model Oops
$ bin/rails generate model Oops
invoke active_record
create db/migrate/20120528062523_create_oops.rb
create app/models/oops.rb
@ -433,7 +433,7 @@ $ rails generate model Oops
create test/fixtures/oops.yml
```
```bash
$ rails destroy model Oops
$ bin/rails destroy model Oops
invoke active_record
remove db/migrate/20120528062523_create_oops.rb
remove app/models/oops.rb
@ -447,7 +447,7 @@ $ rails destroy model Oops
`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
$ rails about
$ bin/rails about
About your application's environment
Rails version 6.0.0
Ruby version 2.5.0 (x86_64-linux)
@ -480,7 +480,7 @@ More information about migrations can be found in the [Migrations](active_record
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`.
```bash
$ rails notes
$ bin/rails notes
app/controllers/admin/users_controller.rb:
* [ 20] [TODO] any other way to do this?
* [132] [FIXME] high priority for next deploy
@ -496,7 +496,7 @@ You can pass specific annotations by using the `--annotations` argument. By defa
Note that annotations are case sensitive.
```bash
$ rails notes --annotations FIXME RELEASE
$ 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
@ -530,7 +530,7 @@ config.annotations.register_directories("spec", "vendor")
```
```bash
$ rails notes
$ bin/rails notes
app/controllers/admin/users_controller.rb:
* [ 20] [TODO] any other way to do this?
* [132] [FIXME] high priority for next deploy
@ -555,7 +555,7 @@ config.annotations.register_extensions("scss", "sass") { |annotation| /\/\/\s*(#
```
```bash
$ rails notes
$ bin/rails notes
app/controllers/admin/users_controller.rb:
* [ 20] [TODO] any other way to do this?
* [132] [FIXME] high priority for next deploy
@ -593,25 +593,25 @@ The `Rails.root/tmp` directory is, like the *nix /tmp directory, the holding pla
The `tmp:` namespaced commands will help you clear and create the `Rails.root/tmp` directory:
* `rails tmp:cache:clear` clears `tmp/cache`.
* `rails tmp:sockets:clear` clears `tmp/sockets`.
* `rails tmp:screenshots:clear` clears `tmp/screenshots`.
* `rails tmp:clear` clears all cache, sockets, and screenshot files.
* `rails tmp:create` creates tmp directories for cache, sockets, and pids.
* `bin/rails tmp:cache:clear` clears `tmp/cache`.
* `bin/rails tmp:sockets:clear` clears `tmp/sockets`.
* `bin/rails tmp:screenshots:clear` clears `tmp/screenshots`.
* `bin/rails tmp:clear` clears all cache, sockets, and screenshot files.
* `bin/rails tmp:create` creates tmp directories for cache, sockets, and pids.
### Miscellaneous
* `rails initializers` prints out all defined initializers in the order they are invoked by Rails.
* `rails middleware` lists Rack middleware stack enabled for your app.
* `rails stats` is great for looking at statistics on your code, displaying things like KLOCs (thousands of lines of code) and your code to test ratio.
* `rails secret` will give you a pseudo-random key to use for your session secret.
* `rails time:zones:all` lists all the timezones Rails knows about.
* `bin/rails initializers` prints out all defined initializers in the order they are invoked by Rails.
* `bin/rails middleware` lists Rack middleware stack enabled for your app.
* `bin/rails stats` is great for looking at statistics on your code, displaying things like KLOCs (thousands of lines of code) and your code to test ratio.
* `bin/rails secret` will give you a pseudo-random key to use for your session secret.
* `bin/rails time:zones:all` lists all the timezones Rails knows about.
### Custom Rake Tasks
Custom rake tasks have a `.rake` extension and are placed in
`Rails.root/lib/tasks`. You can create these custom rake tasks with the
`rails generate task` command.
`bin/rails generate task` command.
```ruby
desc "I am short, but comprehensive description for my cool task"
@ -643,9 +643,9 @@ end
Invocation of the tasks will look like:
```bash
$ rails task_name
$ rails "task_name[value 1]" # entire argument string should be quoted
$ rails db:nothing
$ bin/rails task_name
$ bin/rails "task_name[value 1]" # entire argument string should be quoted
$ bin/rails db:nothing
```
NOTE: If you need to interact with your application models, perform database queries, and so on, your task should depend on the `environment` task, which will load your application code.

View file

@ -218,10 +218,10 @@ The full set of methods that can be used in this block are as follows:
* `integration_tool` defines which integration tool to use to generate integration tests. Defaults to `:test_unit`.
* `system_tests` defines which integration tool to use to generate system tests. Defaults to `:test_unit`.
* `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 e.g. sass) to be used when generating assets. Defaults to `:css`.
* `scaffold_stylesheet` creates `scaffold.css` when generating a scaffolded resource. Defaults to `true`.
@ -1019,10 +1019,10 @@ development:
$ echo $DATABASE_URL
postgresql://localhost/my_database
$ rails runner 'puts ActiveRecord::Base.configurations'
$ bin/rails runner 'puts ActiveRecord::Base.configurations'
#<ActiveRecord::DatabaseConfigurations:0x00007fd50e209a28>
$ rails runner 'puts ActiveRecord::Base.configurations.inspect'
$ bin/rails runner 'puts ActiveRecord::Base.configurations.inspect'
#<ActiveRecord::DatabaseConfigurations:0x00007fc8eab02880 @configurations=[
#<ActiveRecord::DatabaseConfigurations::UrlConfig:0x00007fc8eab020b0
@env_name="development", @spec_name="primary",
@ -1044,10 +1044,10 @@ development:
$ echo $DATABASE_URL
postgresql://localhost/my_database
$ rails runner 'puts ActiveRecord::Base.configurations'
$ bin/rails runner 'puts ActiveRecord::Base.configurations'
#<ActiveRecord::DatabaseConfigurations:0x00007fd50e209a28>
$ rails runner 'puts ActiveRecord::Base.configurations.inspect'
$ bin/rails runner 'puts ActiveRecord::Base.configurations.inspect'
#<ActiveRecord::DatabaseConfigurations:0x00007fc8eab02880 @configurations=[
#<ActiveRecord::DatabaseConfigurations::UrlConfig:0x00007fc8eab020b0
@env_name="development", @spec_name="primary",
@ -1068,10 +1068,10 @@ development:
$ echo $DATABASE_URL
postgresql://localhost/my_database
$ rails runner 'puts ActiveRecord::Base.configurations'
$ bin/rails runner 'puts ActiveRecord::Base.configurations'
#<ActiveRecord::DatabaseConfigurations:0x00007fd50e209a28>
$ rails runner 'puts ActiveRecord::Base.configurations.inspect'
$ bin/rails runner 'puts ActiveRecord::Base.configurations.inspect'
#<ActiveRecord::DatabaseConfigurations:0x00007fc8eab02880 @configurations=[
#<ActiveRecord::DatabaseConfigurations::UrlConfig:0x00007fc8eab020b0
@env_name="development", @spec_name="primary",

View file

@ -217,7 +217,7 @@ irb(main):001:0> Article.pamplemousse
=> #<Comment id: 2, author: "1", body: "Well, actually...", article_id: 1, created_at: "2018-10-19 00:56:10", updated_at: "2018-10-19 00:56:10">
```
After running `ActiveRecord::Base.verbose_query_logs = true` in the `rails console` session to enable verbose query logs and running the method again, it becomes obvious what single line of code is generating all these discrete database calls:
After running `ActiveRecord::Base.verbose_query_logs = true` in the `bin/rails console` session to enable verbose query logs and running the method again, it becomes obvious what single line of code is generating all these discrete database calls:
```
irb(main):003:0> Article.pamplemousse
@ -351,7 +351,7 @@ For example:
```bash
=> 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

View file

@ -202,7 +202,7 @@ within the `Engine` class definition. Without it, classes generated in an engine
**may** conflict with an application.
What this isolation of the namespace means is that a model generated by a call
to `rails generate model`, such as `rails generate model article`, won't be called `Article`, but
to `bin/rails generate model`, such as `bin/rails generate model article`, won't be called `Article`, but
instead be namespaced and called `Blorgh::Article`. In addition, the table for the
model is namespaced, becoming `blorgh_articles`, rather than simply `articles`.
Similar to the model namespacing, a controller called `ArticlesController` becomes
@ -344,7 +344,7 @@ The first thing to generate for a blog engine is the `Article` model and related
controller. To quickly generate this, you can use the Rails scaffold generator.
```bash
$ rails generate scaffold article title:string text:text
$ bin/rails generate scaffold article title:string text:text
```
This command will output this information:
@ -445,14 +445,14 @@ an article resource as well.
Finally, the assets for this resource are generated in one file: `app/assets/stylesheets/blorgh/articles.css`. You'll see how to use these a little later.
You can see what the engine has so far by running `rails db:migrate` at the root
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`.
@ -487,7 +487,7 @@ From the application root, run the model generator. Tell it to generate a
and `text` text column.
```bash
$ rails generate model Comment article_id:integer text:text
$ bin/rails generate model Comment article_id:integer text:text
```
This will output the following:
@ -507,7 +507,7 @@ called `Blorgh::Comment`. Now run the migration to create our blorgh_comments
table:
```bash
$ rails db:migrate
$ bin/rails db:migrate
```
To show the comments on an article, edit `app/views/blorgh/articles/show.html.erb` and
@ -581,7 +581,7 @@ The route now exists, but the controller that this route goes to does not. To
create it, run this command from the application root:
```bash
$ rails generate controller comments
$ bin/rails generate controller comments
```
This will generate the following things:
@ -699,7 +699,7 @@ mount Blorgh::Engine, at: "/blog"
```
This line will mount the engine at `/blog` in the application. Making it
accessible at `http://localhost:3000/blog` when the application runs with `rails
accessible at `http://localhost:3000/blog` when the application runs with `bin/rails
server`.
NOTE: Other engines, such as Devise, handle this a little differently by making
@ -715,14 +715,14 @@ engine's models can query them correctly. To copy these migrations into the
application run the following command from the application's root:
```bash
$ rails blorgh:install:migrations
$ bin/rails blorgh:install:migrations
```
If you have multiple engines that need migrations copied over, use
`railties:install:migrations` instead:
```bash
$ rails railties:install:migrations
$ bin/rails railties:install:migrations
```
This command, when run for the first time, will copy over all the migrations
@ -740,7 +740,7 @@ timestamp (`[timestamp_2]`) will be the current time plus a second. The reason
for this is so that the migrations for the engine are run after any existing
migrations in the application.
To run these migrations within the context of the application, simply run `rails
To run these migrations within the context of the application, simply run `bin/rails
db:migrate`. When accessing the engine through `http://localhost:3000/blog`, the
articles will be empty. This is because the table created inside the application is
different from the one created within the engine. Go ahead, play around with the
@ -751,14 +751,14 @@ If you would like to run migrations only from one engine, you can do it by
specifying `SCOPE`:
```bash
$ rails db:migrate SCOPE=blorgh
$ bin/rails db:migrate SCOPE=blorgh
```
This may be useful if you want to revert engine's migrations before removing it.
To revert all migrations from blorgh engine you can run code such as:
```bash
$ rails db:migrate SCOPE=blorgh VERSION=0
$ bin/rails db:migrate SCOPE=blorgh VERSION=0
```
### Using a Class Provided by the Application
@ -782,10 +782,10 @@ configurable further on). It can be generated using this command inside the
application:
```bash
$ rails generate model user name:string
$ bin/rails generate model user name:string
```
The `rails db:migrate` command needs to be run here to ensure that our
The `bin/rails db:migrate` command needs to be run here to ensure that our
application has the `users` table for future use.
Also, to keep it simple, the articles form will have a new text field called
@ -845,7 +845,7 @@ of associating the records in the `blorgh_articles` table with the records in th
To generate this new column, run this command within the engine:
```bash
$ rails generate migration add_author_id_to_blorgh_articles author_id:integer
$ bin/rails generate migration add_author_id_to_blorgh_articles author_id:integer
```
NOTE: Due to the migration's name and the column specification after it, Rails
@ -857,7 +857,7 @@ This migration will need to be run on the application. To do that, it must first
be copied using this command:
```bash
$ rails blorgh:install:migrations
$ bin/rails blorgh:install:migrations
```
Notice that only _one_ migration was copied over here. This is because the first
@ -872,7 +872,7 @@ Copied migration [timestamp]_add_author_id_to_blorgh_articles.blorgh.rb from blo
Run the migration using:
```bash
$ rails db:migrate
$ bin/rails db:migrate
```
Now with all the pieces in place, an action will take place that will associate
@ -1381,7 +1381,7 @@ need to require `admin.css` or `admin.js`. Only the gem's admin layout needs
these assets. It doesn't make sense for the host app to include
`"blorgh/admin.css"` in its stylesheets. In this situation, you should
explicitly define these assets for precompilation. This tells Sprockets to add
your engine assets when `rails assets:precompile` is triggered.
your engine assets when `bin/rails assets:precompile` is triggered.
You can define assets for precompilation in `engine.rb`:

View file

@ -21,18 +21,20 @@ 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
$ cd myapp
$ rails generate
$ bin/rails generate
```
NOTE: To create a rails application we use the `rails` global command, the rails gem installed via `gem install rails`. When inside the directory of your application, we use the command `bin/rails` which uses the bundled rails inside this application.
You will get a list of all generators that comes with Rails. If you need a detailed description of the helper generator, for example, you can simply do:
```bash
$ rails generate helper --help
$ bin/rails generate helper --help
```
Creating Your First Generator
@ -57,13 +59,13 @@ Our new generator is quite simple: it inherits from `Rails::Generators::Base` an
To invoke our new generator, we just need to do:
```bash
$ rails generate initializer
$ bin/rails generate initializer
```
Before we go on, let's see our brand new generator description:
```bash
$ rails generate initializer --help
$ bin/rails generate initializer --help
```
Rails is usually able to generate good descriptions if a generator is namespaced, as `ActiveRecord::Generators::ModelGenerator`, but not in this particular case. We can solve this problem in two ways. The first one is calling `desc` inside our generator:
@ -85,7 +87,7 @@ Creating Generators with Generators
Generators themselves have a generator:
```bash
$ rails generate generator initializer
$ bin/rails generate generator initializer
create lib/generators/initializer
create lib/generators/initializer/initializer_generator.rb
create lib/generators/initializer/USAGE
@ -107,9 +109,9 @@ First, notice that we are inheriting from `Rails::Generators::NamedBase` instead
We can see that by invoking the description of this new generator (don't forget to delete the old generator file):
```bash
$ rails generate initializer --help
$ 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`.
@ -135,7 +137,7 @@ end
And let's execute our generator:
```bash
$ rails generate initializer core_extensions
$ bin/rails generate initializer core_extensions
```
We can see that now an initializer named core_extensions was created at `config/initializers/core_extensions.rb` with the contents of our template. That means that `copy_file` copied a file in our source root to the destination path we gave. The method `file_name` is automatically created when we inherit from `Rails::Generators::NamedBase`.
@ -145,7 +147,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
@ -174,7 +176,7 @@ end
Before we customize our workflow, let's first see what our scaffold looks like:
```bash
$ rails generate scaffold User name:string
$ bin/rails generate scaffold User name:string
invoke active_record
create db/migrate/20130924151154_create_users.rb
create app/models/user.rb
@ -235,7 +237,7 @@ If we generate another resource with the scaffold generator, we can see that sty
To demonstrate this, we are going to create a new helper generator that simply adds some instance variable readers. First, we create a generator within the rails namespace, as this is where rails searches for generators used as hooks:
```bash
$ rails generate generator rails/my_helper
$ bin/rails generate generator rails/my_helper
create lib/generators/rails/my_helper
create lib/generators/rails/my_helper/my_helper_generator.rb
create lib/generators/rails/my_helper/USAGE
@ -264,7 +266,7 @@ end
We can try out our new generator by creating a helper for products:
```bash
$ rails generate my_helper products
$ bin/rails generate my_helper products
create app/helpers/products_helper.rb
```
@ -291,7 +293,7 @@ end
and see it in action when invoking the generator:
```bash
$ rails generate scaffold Article body:text
$ bin/rails generate scaffold Article body:text
[...]
invoke my_helper
create app/helpers/articles_helper.rb
@ -391,7 +393,7 @@ end
Now, if you create a Comment scaffold, you will see that the shoulda generators are being invoked, and at the end, they are just falling back to TestUnit generators:
```bash
$ rails generate scaffold Comment body:text
$ bin/rails generate scaffold Comment body:text
invoke active_record
create db/migrate/20130924143118_create_comments.rb
create app/models/comment.rb
@ -473,7 +475,7 @@ class_option :scope, type: :string, default: 'read_products'
Now our generator can be invoked as follows:
```bash
$ rails generate initializer --scope write_products
$ bin/rails generate initializer --scope write_products
```
The command line arguments are accessed through the `options` method inside the generator class. e.g:

View file

@ -199,7 +199,7 @@ start a web server on your development machine. You can do this by running the
following in the `blog` directory:
```bash
$ rails server
$ bin/rails server
```
TIP: If you are using Windows, you have to pass the scripts under the `bin`
@ -253,7 +253,7 @@ tell it you want a controller called "Welcome" with an action called "index",
just like this:
```bash
$ rails generate controller Welcome index
$ bin/rails generate controller Welcome index
```
Rails will create several files and a route for you.
@ -324,7 +324,7 @@ end
application to the welcome controller's index action and `get 'welcome/index'`
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 (`rails generate controller Welcome index`).
controller generator (`bin/rails generate controller Welcome index`).
Launch the web server again if you stopped it to generate the controller (`rails
server`) and navigate to <http://localhost:3000> in your browser. You'll see the
@ -360,13 +360,13 @@ Rails.application.routes.draw do
end
```
If you run `rails routes`, you'll see that it has defined routes for all the
If you run `bin/rails routes`, you'll see that it has defined routes for all the
standard RESTful actions. The meaning of the prefix column (and other columns)
will be seen later, but for now notice that Rails has inferred the
singular form `article` and makes meaningful use of the distinction.
```bash
$ rails routes
$ bin/rails routes
Prefix Verb URI Pattern Controller#Action
welcome_index GET /welcome/index(.:format) welcome#index
articles GET /articles(.:format) articles#index
@ -405,7 +405,7 @@ a controller called `ArticlesController`. You can do this by running this
command:
```bash
$ rails generate controller Articles
$ bin/rails generate controller Articles
```
If you open up the newly generated `app/controllers/articles_controller.rb`
@ -554,10 +554,10 @@ this:
In this example, the `articles_path` helper is passed to the `:url` option.
To see what Rails will do with this, we look back at the output of
`rails routes`:
`bin/rails routes`:
```bash
$ rails routes
$ bin/rails routes
Prefix Verb URI Pattern Controller#Action
welcome_index GET /welcome/index(.:format) welcome#index
articles GET /articles(.:format) articles#index
@ -651,7 +651,7 @@ Rails developers tend to use when creating new models. To create the new model,
run this command in your terminal:
```bash
$ rails generate model Article title:string text:text
$ bin/rails generate model Article title:string text:text
```
With that command we told Rails that we want an `Article` model, together
@ -670,7 +670,7 @@ models, as that will be done automatically by Active Record.
### Running a Migration
As we've just seen, `rails generate model` created a _database migration_ file
As we've just seen, `bin/rails generate model` created a _database migration_ file
inside the `db/migrate` directory. Migrations are Ruby classes that are
designed to make it simple to create and modify database tables. Rails uses
rake commands to run migrations, and it's possible to undo a migration after
@ -706,7 +706,7 @@ TIP: For more information about migrations, refer to [Active Record Migrations]
At this point, you can use a rails command to run the migration:
```bash
$ rails db:migrate
$ bin/rails db:migrate
```
Rails will execute this migration command and tell you it created the Articles
@ -723,7 +723,7 @@ NOTE. Because you're working in the development environment by default, this
command will apply to the database defined in the `development` section of your
`config/database.yml` file. If you would like to execute migrations in another
environment, for instance in production, you must explicitly pass it when
invoking the command: `rails db:migrate RAILS_ENV=production`.
invoking the command: `bin/rails db:migrate RAILS_ENV=production`.
### Saving Data in the Controller
@ -811,7 +811,7 @@ If you submit the form again now, Rails will complain about not finding the
`show` action. That's not very useful though, so let's add the `show` action
before proceeding.
As we have seen in the output of `rails routes`, the route for `show` action is
As we have seen in the output of `bin/rails routes`, the route for `show` action is
as follows:
```
@ -873,7 +873,7 @@ Visit <http://localhost:3000/articles/new> and give it a try!
### Listing all Articles
We still need a way to list all our articles, so let's do that.
The route for this as per output of `rails routes` is:
The route for this as per output of `bin/rails routes` is:
```
articles GET /articles(.:format) articles#index
@ -1379,7 +1379,7 @@ Then do the same for the `app/views/articles/edit.html.erb` view:
We're now ready to cover the "D" part of CRUD, deleting articles from the
database. Following the REST convention, the route for
deleting articles as per output of `rails routes` is:
deleting articles as per output of `bin/rails routes` is:
```ruby
DELETE /articles/:id(.:format) articles#destroy
@ -1529,7 +1529,7 @@ the `Article` model. This time we'll create a `Comment` model to hold a
reference to an article. Run this command in your terminal:
```bash
$ rails generate model Comment commenter:string body:text article:references
$ bin/rails generate model Comment commenter:string body:text article:references
```
This command will generate four files:
@ -1580,7 +1580,7 @@ for it, and a foreign key constraint that points to the `id` column of the `arti
table. Go ahead and run the migration:
```bash
$ rails db:migrate
$ bin/rails db:migrate
```
Rails is smart enough to only execute the migrations that have not already been
@ -1656,7 +1656,7 @@ With the model in hand, you can turn your attention to creating a matching
controller. Again, we'll use the same generator we used before:
```bash
$ rails generate controller Comments
$ bin/rails generate controller Comments
```
This creates four files and one empty directory:

View file

@ -18,7 +18,7 @@ After reading this guide, you will know:
This guide goes through every method call that is
required to boot up the Ruby on Rails stack for a default Rails
application, explaining each part in detail along the way. For this
guide, we will be focusing on what happens when you execute `rails server`
guide, we will be focusing on what happens when you execute `bin/rails server`
to boot your app.
NOTE: Paths in this guide are relative to Rails or a Rails application unless otherwise specified.

View file

@ -138,7 +138,7 @@ To test that your method does what it says it does, run the unit tests with `bin
To see this in action, change to the `test/dummy` directory, fire up a console, and start squawking:
```bash
$ rails console
$ bin/rails console
>> "Hello World".to_squawk
=> "squawk! Hello World"
```
@ -241,8 +241,8 @@ We can easily generate these models in our "dummy" Rails application by running
```bash
$ cd test/dummy
$ rails generate model Hickwall last_squawk:string
$ rails generate model Wickwall last_squawk:string last_tweet:string
$ bin/rails generate model Hickwall last_squawk:string
$ bin/rails generate model Wickwall last_squawk:string last_tweet:string
```
Now you can create the necessary database tables in your testing database by navigating to your dummy app
@ -250,7 +250,7 @@ and migrating the database. First, run:
```bash
$ cd test/dummy
$ rails db:migrate
$ bin/rails db:migrate
```
While you are here, change the Hickwall and Wickwall models so that they know that they are supposed to act

View file

@ -25,8 +25,8 @@ $ rails new blog -m http://example.com/template.rb
You can use the `app:template` rails command to apply templates to an existing Rails application. The location of the template needs to be passed in via the LOCATION environment variable. Again, this can either be path to a file or a URL.
```bash
$ rails app:template LOCATION=~/template.rb
$ rails app:template LOCATION=http://example.com/template.rb
$ bin/rails app:template LOCATION=~/template.rb
$ bin/rails app:template LOCATION=http://example.com/template.rb
```
Template API

View file

@ -97,7 +97,7 @@ but is built for better flexibility and more features to meet Rails' requirement
Rails has a handy command for inspecting the middleware stack in use:
```bash
$ rails middleware
$ bin/rails middleware
```
For a freshly generated Rails application, this might produce something like:
@ -181,7 +181,7 @@ And now if you inspect the middleware stack, you'll find that `Rack::Runtime` is
not a part of it.
```bash
$ rails middleware
$ bin/rails middleware
(in /Users/lifo/Rails/blog)
use ActionDispatch::Static
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x00000001c304c8>

View file

@ -1209,7 +1209,7 @@ Rails offers facilities for inspecting and testing your routes.
### Listing Existing Routes
To get a complete list of the available routes in your application, visit `http://localhost:3000/rails/info/routes` in your browser while your server is running in the **development** environment. You can also execute the `rails routes` command in your terminal to produce the same output.
To get a complete list of the available routes in your application, visit `http://localhost:3000/rails/info/routes` in your browser while your server is running in the **development** environment. You can also execute the `bin/rails routes` command in your terminal to produce the same output.
Both methods will list all of your routes, in the same order that they appear in `config/routes.rb`. For each route, you'll see:
@ -1218,7 +1218,7 @@ Both methods will list all of your routes, in the same order that they appear in
* The URL pattern to match
* The routing parameters for the route
For example, here's a small section of the `rails routes` output for a RESTful route:
For example, here's a small section of the `bin/rails routes` output for a RESTful route:
```
users GET /users(.:format) users#index
@ -1257,21 +1257,21 @@ Controller#Action | users#edit
You can search through your routes with the grep option: -g. This outputs any routes that partially match the URL helper method name, the HTTP verb, or the URL path.
```
$ rails routes -g new_comment
$ rails routes -g POST
$ rails routes -g admin
$ bin/rails routes -g new_comment
$ bin/rails routes -g POST
$ bin/rails routes -g admin
```
If you only want to see the routes that map to a specific controller, there's the -c option.
```
$ rails routes -c users
$ rails routes -c admin/users
$ rails routes -c Comments
$ rails routes -c Articles::CommentsController
$ bin/rails routes -c users
$ bin/rails routes -c admin/users
$ bin/rails routes -c Comments
$ bin/rails routes -c Articles::CommentsController
```
TIP: You'll find that the output from `rails routes` is much more readable if you widen your terminal window until the output lines don't wrap.
TIP: You'll find that the output from `bin/rails routes` is much more readable if you widen your terminal window until the output lines don't wrap.
### Testing Routes

View file

@ -100,7 +100,7 @@ verification key used for
[signed](https://api.rubyonrails.org/classes/ActionDispatch/Cookies/ChainedCookieJars.html#method-i-signed)
cookies, is derived from the `secret_key_base` configuration value.
TIP: Secrets must be long and random. Use `rails secret` to get new unique secrets.
TIP: Secrets must be long and random. Use `bin/rails secret` to get new unique secrets.
INFO: Learn more about [managing credentials later in this guide](security.html#custom-credentials)

View file

@ -65,12 +65,12 @@ NOTE: Your tests are run under `RAILS_ENV=test`.
### Rails meets Minitest
If you remember, we used the `rails generate model` command in the
If you remember, we used the `bin/rails generate model` command in the
[Getting Started with Rails](getting_started.html) guide. We created our first
model, and among other things it created test stubs in the `test` directory:
```bash
$ rails generate model article title:string body:text
$ bin/rails generate model article title:string body:text
...
create app/models/article.rb
create test/models/article_test.rb
@ -156,7 +156,7 @@ end
Let us run this newly added test (where `6` is the number of line where the test is defined).
```bash
$ rails test test/models/article_test.rb:6
$ bin/rails test test/models/article_test.rb:6
Run options: --seed 44656
# Running:
@ -206,7 +206,7 @@ end
Now the test should pass. Let us verify by running the test again:
```bash
$ rails test test/models/article_test.rb:6
$ bin/rails test test/models/article_test.rb:6
Run options: --seed 31252
# Running:
@ -239,7 +239,7 @@ end
Now you can see even more output in the console from running the tests:
```bash
$ rails test test/models/article_test.rb
$ bin/rails test test/models/article_test.rb
Run options: --seed 1808
# Running:
@ -276,7 +276,7 @@ code. However there are situations when you want to see the full
backtrace. Set the `-b` (or `--backtrace`) argument to enable this behavior:
```bash
$ rails test -b test/models/article_test.rb
$ bin/rails test -b test/models/article_test.rb
```
If we want this test to pass we can modify it to use `assert_raises` like so:
@ -381,12 +381,12 @@ documentation](http://docs.seattlerb.org/minitest).
### The Rails Test Runner
We can run all of our tests at once by using the `rails test` command.
We can run all of our tests at once by using the `bin/rails test` command.
Or we can run a single test file by passing the `rails test` command the filename containing the test cases.
Or we can run a single test file by passing the `bin/rails test` command the filename containing the test cases.
```bash
$ rails test test/models/article_test.rb
$ bin/rails test test/models/article_test.rb
Run options: --seed 1559
# Running:
@ -404,7 +404,7 @@ You can also run a particular test method from the test case by providing the
`-n` or `--name` flag and the test's method name.
```bash
$ rails test test/models/article_test.rb -n test_the_truth
$ bin/rails test test/models/article_test.rb -n test_the_truth
Run options: -n test_the_truth --seed 43583
# Running:
@ -419,20 +419,20 @@ Finished tests in 0.009064s, 110.3266 tests/s, 110.3266 assertions/s.
You can also run a test at a specific line by providing the line number.
```bash
$ rails test test/models/article_test.rb:6 # run specific test and line
$ bin/rails test test/models/article_test.rb:6 # run specific test and line
```
You can also run an entire directory of tests by providing the path to the directory.
```bash
$ rails test test/controllers # run all tests from specific directory
$ bin/rails test test/controllers # run all tests from specific directory
```
The test runner also provides a lot of other features like failing fast, deferring test output
at the end of test run and so on. Check the documentation of the test runner as follows:
```bash
$ rails test -h
$ bin/rails test -h
Usage: rails test [options] [files or directories]
You can run a single test by appending a line number to a filename:
@ -562,11 +562,11 @@ structure. The test helper checks whether your test database has any pending
migrations. It will try to load your `db/schema.rb` or `db/structure.sql`
into the test database. If migrations are still pending, an error will be
raised. Usually this indicates that your schema is not fully migrated. Running
the migrations against the development database (`rails db:migrate`) will
the migrations against the development database (`bin/rails db:migrate`) will
bring the schema up to date.
NOTE: If there were modifications to existing migrations, the test database needs to
be rebuilt. This can be done by executing `rails db:test:prepare`.
be rebuilt. This can be done by executing `bin/rails db:test:prepare`.
### The Low-Down on Fixtures
@ -580,7 +580,7 @@ _Fixtures_ is a fancy word for sample data. Fixtures allow you to populate your
NOTE: Fixtures are not designed to create every object that your tests need, and are best managed when only used for default data that can be applied to the common case.
You'll find fixtures under your `test/fixtures` directory. When you run `rails generate model` to create a new model, Rails automatically creates fixture stubs in this directory.
You'll find fixtures under your `test/fixtures` directory. When you run `bin/rails generate model` to create a new model, Rails automatically creates fixture stubs in this directory.
#### YAML
@ -679,7 +679,7 @@ Rails model tests are stored under the `test/models` directory. Rails provides
a generator to create a model test skeleton for you.
```bash
$ rails generate test_unit:model article title:string body:text
$ bin/rails generate test_unit:model article title:string body:text
create test/models/article_test.rb
create test/fixtures/articles.yml
```
@ -696,7 +696,7 @@ For creating Rails system tests, you use the `test/system` directory in your
application. Rails provides a generator to create a system test skeleton for you.
```bash
$ rails generate system_test users
$ bin/rails generate system_test users
invoke test_unit
create test/system/users_test.rb
```
@ -797,7 +797,7 @@ created for you. If you didn't use the scaffold generator, start by creating a
system test skeleton.
```bash
$ rails generate system_test articles
$ bin/rails generate system_test articles
```
It should have created a test file placeholder for us. With the output of the
@ -829,8 +829,8 @@ Run the system tests.
rails test:system
```
NOTE: By default, running `rails test` won't run your system tests.
Make sure to run `rails test:system` to actually run them.
NOTE: By default, running `bin/rails test` won't run your system tests.
Make sure to run `bin/rails test:system` to actually run them.
#### Creating Articles System Test
@ -909,7 +909,7 @@ Integration tests are used to test how various parts of your application interac
For creating Rails integration tests, we use the `test/integration` directory for our application. Rails provides a generator to create an integration test skeleton for us.
```bash
$ rails generate integration_test user_flows
$ bin/rails generate integration_test user_flows
exists test/integration/
create test/integration/user_flows_test.rb
```
@ -945,7 +945,7 @@ Let's add an integration test to our blog application. We'll start with a basic
We'll start by generating our integration test skeleton:
```bash
$ rails generate integration_test blog_flow
$ bin/rails generate integration_test blog_flow
```
It should have created a test file placeholder for us. With the output of the
@ -1033,7 +1033,7 @@ You should test for things such as:
The easiest way to see functional tests in action is to generate a controller using the scaffold generator:
```bash
$ rails generate scaffold_controller article title:string body:text
$ bin/rails generate scaffold_controller article title:string body:text
...
create app/controllers/articles_controller.rb
...
@ -1049,7 +1049,7 @@ If you already have a controller and just want to generate the test scaffold cod
each of the seven default actions, you can use the following command:
```bash
$ rails generate test_unit:scaffold article
$ bin/rails generate test_unit:scaffold article
...
invoke test_unit
create test/controllers/articles_controller_test.rb
@ -1223,7 +1223,7 @@ end
If we run our test now, we should see a failure:
```bash
$ rails test test/controllers/articles_controller_test.rb -n test_should_create_article
$ bin/rails test test/controllers/articles_controller_test.rb -n test_should_create_article
Run options: -n test_should_create_article --seed 32266
# Running:
@ -1261,7 +1261,7 @@ end
Now if we run our tests, we should see it pass:
```bash
$ rails test test/controllers/articles_controller_test.rb -n test_should_create_article
$ bin/rails test test/controllers/articles_controller_test.rb -n test_should_create_article
Run options: -n test_should_create_article --seed 18981
# Running:

View file

@ -51,7 +51,7 @@ This will help you with the creation of new files and changes of old files in an
interactive session.
```bash
$ rails app:update
$ bin/rails app:update
identical config/boot.rb
exist config
conflict config/routes.rb

View file

@ -68,7 +68,7 @@ and may also be used independently outside \Rails.
3. Change directory to +myapp+ and start the web server:
$ cd myapp
$ rails server
$ bin/rails server
Run with <tt>--help</tt> or <tt>-h</tt> for options.

View file

@ -572,7 +572,7 @@ module Rails
elsif secret_key_base
raise ArgumentError, "`secret_key_base` for #{Rails.env} environment must be a type of String`"
else
raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `rails credentials:edit`"
raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `bin/rails credentials:edit`"
end
end

View file

@ -14,7 +14,7 @@ that just contains the secret_key_base used by MessageVerifiers/MessageEncryptor
signing and encrypting cookies.
For applications created prior to Rails 5.2, we'll automatically generate a new
credentials file in `config/credentials.yml.enc` the first time you run `rails credentials:edit`.
credentials file in `config/credentials.yml.enc` the first time you run `bin/rails credentials:edit`.
If you didn't have a master key saved in `config/master.key`, that'll be created too.
Don't lose this master key! Put it in a password manager your team can access.
@ -60,7 +60,7 @@ The `credentials` command supports passing an `--environment` option to create a
environment specific override. That override will take precedence over the
global `config/credentials.yml.enc` file when running in that environment. So:
rails credentials:edit --environment development
bin/rails credentials:edit --environment development
will create `config/credentials/development.yml.enc` with the corresponding
encryption key in `config/credentials/development.key` if the credentials file

View file

@ -77,9 +77,9 @@ module Rails
def missing_encrypted_message(key:, key_path:, file_path:)
if key.nil?
"Missing '#{key_path}' to decrypt data. See `rails encrypted:help`"
"Missing '#{key_path}' to decrypt data. See `bin/rails encrypted:help`"
else
"File '#{file_path}' does not exist. Use `rails encrypted:edit #{file_path}` to change that."
"File '#{file_path}' does not exist. Use `bin/rails encrypted:edit #{file_path}` to change that."
end
end
end

View file

@ -7,7 +7,7 @@ with the code.
=== Setup
Run `rails secrets:setup` to opt in and generate the `config/secrets.yml.key`
Run `bin/rails secrets:setup` to opt in and generate the `config/secrets.yml.key`
and `config/secrets.yml.enc` files.
The latter contains all the keys to be encrypted while the former holds the
@ -45,12 +45,12 @@ the key. Add this:
config.read_encrypted_secrets = true
to the environment you'd like to read encrypted secrets. `rails secrets:setup`
to the environment you'd like to read encrypted secrets. `bin/rails secrets:setup`
inserts this into the production environment by default.
=== Editing Secrets
After `rails secrets:setup`, run `rails secrets:edit`.
After `bin/rails secrets:setup`, run `bin/rails secrets:edit`.
That command opens a temporary file in `$EDITOR` with the decrypted contents of
`config/secrets.yml.enc` to edit the encrypted secrets.

View file

@ -288,7 +288,7 @@ module Rails
gem "#{server}"
Run `rails server --help` for more options.
Run `bin/rails server --help` for more options.
MSG
else
suggestion = Rails::Command::Spellchecker.suggest(server, from: RACK_SERVERS)
@ -296,7 +296,7 @@ module Rails
<<~MSG
Could not find server "#{server}". #{suggestion_msg}
Run `rails server --help` for more options.
Run `bin/rails server --help` for more options.
MSG
end
end
@ -305,7 +305,7 @@ module Rails
say <<~MSG
=> Booting #{ActiveSupport::Inflector.demodulize(server)}
=> Rails #{Rails.version} application starting in #{Rails.env} #{url}
=> Run `rails server --help` for more startup options
=> Run `bin/rails server --help` for more startup options
MSG
end
end

View file

@ -275,7 +275,7 @@ module Rails
puts <<~MSG
Could not find generator '#{namespace}'. #{suggestion_msg}
Run `rails generate --help` for more options.
Run `bin/rails generate --help` for more options.
MSG
end
end

View file

@ -1,5 +1,5 @@
// 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.
import { createConsumer } from "@rails/actioncable"

View file

@ -10,8 +10,7 @@ Description:
If Sass 3 is available, stylesheets will be generated with the .scss extension.
Example:
`rails generate assets posts`
`bin/rails generate assets posts`
Posts assets.
Stylesheet: app/assets/stylesheets/posts.css

View file

@ -9,7 +9,7 @@ Description:
template engine, assets, and test framework generators.
Example:
`rails generate controller CreditCards open debit credit close`
`bin/rails generate controller CreditCards open debit credit close`
CreditCards controller with URLs like /credit_cards/debit.
Controller: app/controllers/credit_cards_controller.rb

View file

@ -20,7 +20,7 @@ module Rails
add_credentials_file_silently(template)
say "You can edit encrypted credentials with `rails credentials:edit`."
say "You can edit encrypted credentials with `bin/rails credentials:edit`."
say ""
end
end

View file

@ -3,7 +3,7 @@ Description:
either CamelCased or snake_cased.
Example:
`rails generate generator Awesome`
`bin/rails generate generator Awesome`
creates a standard awesome generator:
lib/generators/awesome/

View file

@ -2,7 +2,7 @@ Description:
Explain the generator
Example:
rails generate <%= file_name %> Thing
bin/rails generate <%= file_name %> Thing
This will create:
what/will/it/create

View file

@ -6,8 +6,7 @@ Description:
path like 'parent_module/helper_name'.
Example:
`rails generate helper CreditCard`
`bin/rails generate helper CreditCard`
Credit card helper.
Helper: app/helpers/credit_card_helper.rb

View file

@ -6,5 +6,5 @@ Description:
TestUnit.
Example:
`rails generate integration_test GeneralStories` creates a GeneralStories
`bin/rails generate integration_test GeneralStories` creates a GeneralStories
integration test in test/integration/general_stories_test.rb

View file

@ -8,12 +8,12 @@ Description:
column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable
Example:
`rails generate migration AddSslFlag`
`bin/rails generate migration AddSslFlag`
If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration
db/migrate/20080514090912_add_ssl_flag.rb
`rails generate migration AddTitleBodyToPost title:string body:text published:boolean`
`bin/rails generate migration AddTitleBodyToPost title:string body:text published:boolean`
This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with this in the Change migration:
@ -25,7 +25,7 @@ Migration names containing JoinTable will generate join tables for use with
has_and_belongs_to_many associations.
Example:
`rails g migration CreateMediaJoinTable artists musics:uniq`
`bin/rails g migration CreateMediaJoinTable artists musics:uniq`
will create the migration

View file

@ -29,7 +29,7 @@ Available field types:
Just after the field name you can specify a type like text or boolean.
It will generate the column with the associated SQL type. For instance:
`rails generate model post title:string body:text`
`bin/rails generate model post title:string body:text`
will generate a title column with a varchar type and a body column with a text
type. If no type is specified the string type will be used by default.
@ -49,47 +49,47 @@ Available field types:
You can also consider `references` as a kind of type. For instance, if you run:
`rails generate model photo title:string album:references`
`bin/rails generate model photo title:string album:references`
It will generate an `album_id` column. You should generate these kinds of fields when
you will use a `belongs_to` association, for instance. `references` also supports
polymorphism, you can enable polymorphism like this:
`rails generate model product supplier:references{polymorphic}`
`bin/rails generate model product supplier:references{polymorphic}`
For integer, string, text and binary fields, an integer in curly braces will
be set as the limit:
`rails generate model user pseudo:string{30}`
`bin/rails generate model user pseudo:string{30}`
For decimal, two integers separated by a comma in curly braces will be used
for precision and scale:
`rails generate model product 'price:decimal{10,2}'`
`bin/rails generate model product 'price:decimal{10,2}'`
You can add a `:uniq` or `:index` suffix for unique or standard indexes
respectively:
`rails generate model user pseudo:string:uniq`
`rails generate model user pseudo:string:index`
`bin/rails generate model user pseudo:string:uniq`
`bin/rails generate model user pseudo:string:index`
You can combine any single curly brace option with the index options:
`rails generate model user username:string{30}:uniq`
`rails generate model product supplier:references{polymorphic}:index`
`bin/rails generate model user username:string{30}:uniq`
`bin/rails generate model product supplier:references{polymorphic}:index`
If you require a `password_digest` string column for use with
has_secure_password, you can specify `password:digest`:
`rails generate model user password:digest`
`bin/rails generate model user password:digest`
If you require a `token` string column for use with
has_secure_token, you can specify `auth_token:token`:
`rails generate model user auth_token:token`
`bin/rails generate model user auth_token:token`
Examples:
`rails generate model account`
`bin/rails generate model account`
For Active Record and TestUnit it creates:
@ -98,11 +98,11 @@ Examples:
Fixtures: test/fixtures/accounts.yml
Migration: db/migrate/XXX_create_accounts.rb
`rails generate model post title:string body:text published:boolean`
`bin/rails generate model post title:string body:text published:boolean`
Creates a Post model with a string title, text body, and published flag.
`rails generate model admin/account`
`bin/rails generate model admin/account`
For Active Record and TestUnit it creates:
@ -111,4 +111,3 @@ Examples:
Test: test/models/admin/account_test.rb
Fixtures: test/fixtures/admin/accounts.yml
Migration: db/migrate/XXX_create_admin_accounts.rb

View file

@ -18,6 +18,6 @@ Description:
views or add any methods to the generated controller.
Examples:
`rails generate resource post` # no attributes
`rails generate resource post title:string body:text published:boolean`
`rails generate resource purchase order_id:integer amount:decimal`
`bin/rails generate resource post` # no attributes
`bin/rails generate resource post title:string body:text published:boolean`
`bin/rails generate resource purchase order_id:integer amount:decimal`

View file

@ -5,7 +5,7 @@ module Rails
class ResourceRouteGenerator < NamedBase # :nodoc:
# Properly nests namespaces passed into a generator
#
# $ rails generate resource admin/users/products
# $ bin/rails generate resource admin/users/products
#
# should give you
#

View file

@ -32,10 +32,10 @@ Description:
in config/routes.rb.
If you want to remove all the generated files, run
'rails destroy scaffold ModelName'.
'bin/rails destroy scaffold ModelName'.
Examples:
`rails generate scaffold post`
`rails generate scaffold post title:string body:text published:boolean`
`rails generate scaffold purchase amount:decimal tracking_id:integer:uniq`
`rails generate scaffold user email:uniq password:digest`
`bin/rails generate scaffold post`
`bin/rails generate scaffold post title:string body:text published:boolean`
`bin/rails generate scaffold purchase amount:decimal tracking_id:integer:uniq`
`bin/rails generate scaffold user email:uniq password:digest`

View file

@ -10,7 +10,7 @@ Description:
template engine and test framework generators.
Example:
`rails generate scaffold_controller CreditCard`
`bin/rails generate scaffold_controller CreditCard`
Credit card controller with URLs like /credit_cards.
Controller: app/controllers/credit_cards_controller.rb

View file

@ -6,5 +6,5 @@ Description:
TestUnit.
Example:
`rails generate system_test GeneralStories` creates a GeneralStories
`bin/rails generate system_test GeneralStories` creates a GeneralStories
system test in test/system/general_stories_test.rb

View file

@ -4,6 +4,6 @@ Description:
This generates a task file in lib/tasks.
Example:
`rails generate task feeds fetch erase add`
`bin/rails generate task feeds fetch erase add`
Task: lib/tasks/feeds.rake
Task: lib/tasks/feeds.rake

View file

@ -12,7 +12,7 @@ task about: :environment do
end
namespace :time do
desc "List all time zones, list by two-letter country code (`rails time:zones[US]`), or list by UTC offset (`rails time:zones[-8]`)"
desc "List all time zones, list by two-letter country code (`bin/rails time:zones[US]`), or list by UTC offset (`bin/rails time:zones[-8]`)"
task :zones, :country_or_offset do |t, args|
zones, offset = ActiveSupport::TimeZone.all, nil

View file

@ -485,7 +485,7 @@ module ApplicationTests
test "db:schema:load fails if schema.rb doesn't exist yet" do
stderr_output = capture(:stderr) { rails("db:schema:load", stderr: true, allow_failure: true) }
assert_match(/Run `rails db:migrate` to create it/, stderr_output)
assert_match(/Run `bin\/rails db:migrate` to create it/, stderr_output)
end
def db_test_load_structure

View file

@ -653,7 +653,7 @@ module ApplicationTests
create_test_file :models, "account"
create_test_file :models, "post", pass: false
# This specifically verifies TEST for backwards compatibility with rake test
# as `rails test` already supports running tests from a single file more cleanly.
# as `bin/rails test` already supports running tests from a single file more cleanly.
output = Dir.chdir(app_path) { `bin/rake test TEST=test/models/post_test.rb` }
assert_match "PostTest", output, "passing TEST= should run selected test"

View file

@ -7,7 +7,7 @@ class Rails::Command::DevTest < ActiveSupport::TestCase
setup :build_app
teardown :teardown_app
test "`rails dev:cache` creates both caching and restart file when restart file doesn't exist and dev caching is currently off" do
test "`bin/rails dev:cache` creates both caching and restart file when restart file doesn't exist and dev caching is currently off" do
Dir.chdir(app_path) do
assert_not File.exist?("tmp/caching-dev.txt")
assert_not File.exist?("tmp/restart.txt")
@ -21,7 +21,7 @@ class Rails::Command::DevTest < ActiveSupport::TestCase
end
end
test "`rails dev:cache` creates caching file and touches restart file when dev caching is currently off" do
test "`bin/rails dev:cache` creates caching file and touches restart file when dev caching is currently off" do
Dir.chdir(app_path) do
app_file("tmp/restart.txt", "")
@ -39,7 +39,7 @@ class Rails::Command::DevTest < ActiveSupport::TestCase
end
end
test "`rails dev:cache` removes caching file and touches restart file when dev caching is currently on" do
test "`bin/rails dev:cache` removes caching file and touches restart file when dev caching is currently on" do
Dir.chdir(app_path) do
app_file("tmp/caching-dev.txt", "")
app_file("tmp/restart.txt", "")

View file

@ -27,7 +27,7 @@ class GeneratorsTest < Rails::Generators::TestCase
name = :unknown
output = capture(:stdout) { Rails::Generators.invoke name }
assert_match "Could not find generator '#{name}'", output
assert_match "`rails generate --help`", output
assert_match "`bin/rails generate --help`", output
assert_no_match "Maybe you meant", output
end