aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/command_line.md
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2012-09-01 21:37:59 -0400
committerPrem Sichanugrist <s@sikac.hu>2012-09-17 15:54:23 -0400
commit31ef4cf656785a190723d2d8fb4c0fd06f4009bc (patch)
tree582a93b9441b41c1150ae421a2a878194af6475e /guides/source/command_line.md
parented62b1bf0b6fff53524c168f9615af84dea99537 (diff)
downloadrails-31ef4cf656785a190723d2d8fb4c0fd06f4009bc.tar.gz
rails-31ef4cf656785a190723d2d8fb4c0fd06f4009bc.tar.bz2
rails-31ef4cf656785a190723d2d8fb4c0fd06f4009bc.zip
Convert all inline codes to Markdown syntax
Diffstat (limited to 'guides/source/command_line.md')
-rw-r--r--guides/source/command_line.md124
1 files changed, 62 insertions, 62 deletions
diff --git a/guides/source/command_line.md b/guides/source/command_line.md
index 83ed244d49..38b15c9590 100644
--- a/guides/source/command_line.md
+++ b/guides/source/command_line.md
@@ -29,11 +29,11 @@ There are a few commands that are absolutely critical to your everyday usage of
Let's create a simple Rails application to step through each of these commands in context.
-### +rails new+
+### `rails new`
-The first thing we'll want to do is create a new Rails application by running the +rails new+ command after installing Rails.
+The first thing we'll want to do is create a new Rails application by running the `rails new` command after installing Rails.
-INFO: You can install the rails gem by typing +gem install rails+, if you don't have it already.
+INFO: You can install the rails gem by typing `gem install rails`, if you don't have it already.
```bash
$ rails new commandsapp
@@ -52,13 +52,13 @@ $ rails new commandsapp
Rails will set you up with what seems like a huge amount of stuff for such a tiny command! You've got the entire Rails directory structure now with all the code you need to run our simple application right out of the box.
-### +rails server+
+### `rails server`
-The +rails server+ command launches a small web server named WEBrick which comes bundled with Ruby. You'll use this any time you want to access your application through a web browser.
+The `rails server` command launches a small web server named WEBrick which comes bundled with Ruby. You'll use this any time you want to access your application through a web browser.
INFO: WEBrick isn't your only option for serving Rails. We'll get to that "later":#different-servers.
-With no further work, +rails server+ will run our new shiny Rails app:
+With no further work, `rails server` will run our new shiny Rails app:
```bash
$ cd commandsapp
@@ -76,17 +76,17 @@ With just three commands we whipped up a Rails server listening on port 3000. Go
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+.
+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
```
-The +-b+ option binds Rails to the specified ip, by default it is 0.0.0.0. You can run a server as a daemon by passing a +-d+ option.
+The `-b` option binds Rails to the specified ip, by default it is 0.0.0.0. You can run a server as a daemon by passing a `-d` option.
-### +rails generate+
+### `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 `rails generate` command uses templates to create a whole lot of things. Running `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`.
@@ -113,7 +113,7 @@ Using generators will save you a large amount of time by writing *boilerplate co
Let's make our own controller with the controller generator. But what command should we use? Let's ask the generator:
-INFO: All Rails console utilities have help text. As with most *nix utilities, you can try adding +--help+ or +-h+ to the end, for example +rails server --help+.
+INFO: All Rails console utilities have help text. As with most *nix utilities, you can try adding `--help` or `-h` to the end, for example `rails server --help`.
```bash
$ rails generate controller
@@ -140,7 +140,7 @@ Example:
Helper: app/helpers/credit_card_helper.rb
```
-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.
+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
@@ -164,7 +164,7 @@ $ rails generate controller Greetings hello
What all did this generate? It made sure a bunch of directories were in our application, and created a controller file, a view file, a functional test file, a helper for the view, a JavaScript file and a stylesheet file.
-Check out the controller and modify it a little (in +app/controllers/greetings_controller.rb+):
+Check out the controller and modify it a little (in `app/controllers/greetings_controller.rb`):
```ruby
class GreetingsController < ApplicationController
@@ -174,14 +174,14 @@ class GreetingsController < ApplicationController
end
```
-Then the view, to display our message (in +app/views/greetings/hello.html.erb+):
+Then the view, to display our message (in `app/views/greetings/hello.html.erb`):
```html
<h1>A Greeting for You!</h1>
<p><%= @message %></p>
```
-Fire up your server using +rails server+.
+Fire up your server using `rails server`.
```bash
$ rails server
@@ -211,7 +211,7 @@ Description:
Create rails files for model generator.
```
-NOTE: For a list of available field types, refer to the "API documentation":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column for the column method for the +TableDefinition+ class.
+NOTE: For a list of available field types, refer to the "API documentation":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-column for the column method for the `TableDefinition` class.
But instead of generating a model directly (which we'll be doing later), let's set up a scaffold. A *scaffold* in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above.
@@ -250,9 +250,9 @@ $ rails generate scaffold HighScore game:string score:integer
create app/assets/stylesheets/scaffolds.css.scss
```
-The generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the +high_scores+ table and fields), takes care of the route for the *resource*, and new tests for everything.
+The generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the `high_scores` table and fields), takes care of the route for the *resource*, and new tests for everything.
-The migration requires that we *migrate*, that is, run some Ruby code (living in that +20120528060026_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 +rake db:migrate+ command. We'll talk more about Rake in-depth in a little while.
+The migration requires that we *migrate*, that is, run some Ruby code (living in that `20120528060026_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 `rake db:migrate` command. We'll talk more about Rake in-depth in a little while.
```bash
$ rake db:migrate
@@ -272,19 +272,19 @@ $ rails server
Go to your browser and open "http://localhost:3000/high_scores":http://localhost:3000/high_scores, now we can create new high scores (55,160 on Space Invaders!)
-### +rails console+
+### `rails console`
-The +console+ command lets you interact with your Rails application from the command line. On the underside, +rails console+ uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website.
+The `console` command lets you interact with your Rails application from the command line. On the underside, `rails console` uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website.
INFO: You can also use the alias "c" to invoke the console: `rails c`.
-You can specify the environment in which the +console+ command should operate.
+You can specify the environment in which the `console` command should operate.
```bash
$ rails console staging
```
-If you wish to test out some code without changing any data, you can do that by invoking +rails console --sandbox+.
+If you wish to test out some code without changing any data, you can do that by invoking `rails console --sandbox`.
```bash
$ rails console --sandbox
@@ -293,13 +293,13 @@ Any modifications you make will be rolled back on exit
irb(main):001:0>
```
-### +rails dbconsole+
+### `rails dbconsole`
-+rails dbconsole+ figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL, PostgreSQL, SQLite and SQLite3.
+`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, PostgreSQL, SQLite and SQLite3.
INFO: You can also use the alias "db" to invoke the dbconsole: `rails db`.
-### +rails runner+
+### `rails runner`
`runner` runs Ruby code in the context of Rails non-interactively. For instance:
@@ -309,15 +309,15 @@ $ rails runner "Model.long_running_method"
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.
+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"
```
-### +rails destroy+
+### `rails destroy`
-Think of +destroy+ as the opposite of +generate+. It'll figure out what generate did, and undo it.
+Think of `destroy` as the opposite of `generate`. It'll figure out what generate did, and undo it.
INFO: You can also use the alias "d" to invoke the destroy command: `rails d`.
@@ -343,9 +343,9 @@ $ rails destroy model Oops
Rake
----
-Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'make', and uses a 'Rakefile' and +.rake+ files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.
+Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'make', and uses a 'Rakefile' and `.rake` files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.
-You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing +rake --tasks+. Each task has a description, and should help you find the thing you need.
+You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing `rake --tasks`. Each task has a description, and should help you find the thing you need.
```bash
$ rake --tasks
@@ -361,7 +361,7 @@ rake tmp:clear # Clear session, cache, and socket files from tmp/ (narr
rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
```
-### +about+
+### `about`
`rake 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.
@@ -384,27 +384,27 @@ Database adapter sqlite3
Database schema version 20110805173523
```
-### +assets+
+### `assets`
You can precompile the assets in `app/assets` using `rake assets:precompile` and remove those compiled assets using `rake assets:clean`.
-### +db+
+### `db`
-The most common tasks of the +db:+ Rake namespace are +migrate+ and +create+, and it will pay off to try out all of the migration rake tasks (+up+, +down+, +redo+, +reset+). +rake db:version+ is useful when troubleshooting, telling you the current version of the database.
+The most common tasks of the `db:` Rake namespace are `migrate` and `create`, and it will pay off to try out all of the migration rake tasks (`up`, `down`, `redo`, `reset`). `rake db:version` is useful when troubleshooting, telling you the current version of the database.
More information about migrations can be found in the "Migrations":migrations.html guide.
-### +doc+
+### `doc`
-The +doc:+ namespace has the tools to generate documentation for your app, API documentation, guides. Documentation can also be stripped which is mainly useful for slimming your codebase, like if you're writing a Rails application for an embedded platform.
+The `doc:` namespace has the tools to generate documentation for your app, API documentation, guides. Documentation can also be stripped which is mainly useful for slimming your codebase, like if you're writing a Rails application for an embedded platform.
-* +rake doc:app+ generates documentation for your application in +doc/app+.
-* +rake doc:guides+ generates Rails guides in +doc/guides+.
-* +rake doc:rails+ generates API documentation for Rails in +doc/api+.
+* `rake doc:app` generates documentation for your application in `doc/app`.
+* `rake doc:guides` generates Rails guides in `doc/guides`.
+* `rake doc:rails` generates API documentation for Rails in `doc/api`.
-### +notes+
+### `notes`
-+rake notes+ will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. The search is done in files with extension +.builder+, +.rb+, +.erb+, +.haml+ and +.slim+ for both default and custom annotations.
+`rake notes` will search through your code for comments beginning with FIXME, OPTIMIZE or TODO. The search is done in files with extension `.builder`, `.rb`, `.erb`, `.haml` and `.slim` for both default and custom annotations.
```bash
$ rake notes
@@ -418,7 +418,7 @@ app/model/school.rb:
* [ 17] [FIXME]
```
-If you are looking for a specific annotation, say FIXME, you can use +rake notes:fixme+. Note that you have to lower case the annotation's name.
+If you are looking for a specific annotation, say FIXME, you can use `rake notes:fixme`. Note that you have to lower case the annotation's name.
```bash
$ rake notes:fixme
@@ -430,7 +430,7 @@ app/model/school.rb:
* [ 17]
```
-You can also use custom annotations in your code and list them using +rake notes:custom+ by specifying the annotation using an environment variable +ANNOTATION+.
+You can also use custom annotations in your code and list them using `rake notes:custom` by specifying the annotation using an environment variable `ANNOTATION`.
```bash
$ rake notes:custom ANNOTATION=BUG
@@ -441,7 +441,7 @@ app/model/post.rb:
NOTE. When using specific annotations and custom annotations, the annotation name (FIXME, BUG etc) is not displayed in the output lines.
-By default, +rake notes+ will look in the +app+, +config+, +lib+, +script+ and +test+ directories. If you would like to search other directories, you can provide them as a comma separated list in an environment variable +SOURCE_ANNOTATION_DIRECTORIES+.
+By default, `rake notes` will look in the `app`, `config`, `lib`, `script` and `test` directories. If you would like to search other directories, you can provide them as a comma separated list in an environment variable `SOURCE_ANNOTATION_DIRECTORIES`.
```bash
$ export SOURCE_ANNOTATION_DIRECTORIES='rspec,vendor'
@@ -453,31 +453,31 @@ rspec/model/user_spec.rb:
* [122] [TODO] Verify the user that has a subscription works
```
-### +routes+
+### `routes`
-+rake routes+ will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with.
+`rake routes` will list all of your defined routes, which is useful for tracking down routing problems in your app, or giving you a good overview of the URLs in an app you're trying to get familiar with.
-### +test+
+### `test`
INFO: A good description of unit testing in Rails is given in "A Guide to Testing Rails Applications":testing.html
-Rails comes with a test suite called `Test::Unit`. Rails owes its stability to the use of tests. The tasks available in the +test:+ namespace helps in running the different tests you will hopefully write.
+Rails comes with a test suite called `Test::Unit`. Rails owes its stability to the use of tests. The tasks available in the `test:` namespace helps in running the different tests you will hopefully write.
-### +tmp+
+### `tmp`
The `Rails.root/tmp` directory is, like the *nix /tmp directory, the holding place for temporary files like sessions (if you're using a file store for files), process id files, and cached actions.
-The +tmp:+ namespaced tasks will help you clear the `Rails.root/tmp` directory:
+The `tmp:` namespaced tasks will help you clear the `Rails.root/tmp` directory:
-* +rake tmp:cache:clear+ clears `tmp/cache`.
-* +rake tmp:sessions:clear+ clears `tmp/sessions`.
-* +rake tmp:sockets:clear+ clears `tmp/sockets`.
-* +rake tmp:clear+ clears all the three: cache, sessions and sockets.
+* `rake tmp:cache:clear` clears `tmp/cache`.
+* `rake tmp:sessions:clear` clears `tmp/sessions`.
+* `rake tmp:sockets:clear` clears `tmp/sockets`.
+* `rake tmp:clear` clears all the three: cache, sessions and sockets.
### Miscellaneous
-* +rake 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.
-* +rake secret+ will give you a pseudo-random key to use for your session secret.
+* `rake 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.
+* `rake secret` will give you a pseudo-random key to use for your session secret.
* `rake time:zones:all` lists all the timezones Rails knows about.
### Writing Rake Tasks
@@ -486,7 +486,7 @@ If you have (or want to write) any automation scripts outside your app (data imp
INFO: "Complete guide about how to write tasks":http://rake.rubyforge.org/files/doc/rakefile_rdoc.html is available in the official documentation.
-Tasks should be placed in `Rails.root/lib/tasks` and should have a +.rake+ extension.
+Tasks should be placed in `Rails.root/lib/tasks` and should have a `.rake` extension.
Each task should be defined in next format (dependencies are optional):
@@ -525,7 +525,7 @@ rake "task_name[value 1]" # entire argument string should be quoted
rake do:nothing
```
-NOTE: If your 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.
+NOTE: If your 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.
The Rails Advanced Command Line
-------------------------------
@@ -536,7 +536,7 @@ More advanced use of the command line is focused around finding useful (even sur
When creating a new Rails application, you have the option to specify what kind of database and what kind of source code management system your application is going to use. This will save you a few minutes, and certainly many keystrokes.
-Let's see what a +--git+ option and a +--database=postgresql+ option will do for us:
+Let's see what a `--git` option and a `--database=postgresql` option will do for us:
```bash
$ mkdir gitapp
@@ -590,15 +590,15 @@ development:
It also generated some lines in our database.yml configuration corresponding to our choice of PostgreSQL for database.
-NOTE. The only catch with using the SCM options is that you have to make your application's directory first, then initialize your SCM, then you can run the +rails new+ command to generate the basis of your app.
+NOTE. The only catch with using the SCM options is that you have to make your application's directory first, then initialize your SCM, then you can run the `rails new` command to generate the basis of your app.
-### +server+ with Different Backends
+### `server` with Different Backends
Many people have created a large number of different web servers in Ruby, and many of them can be used to run Rails. Since version 2.3, Rails uses Rack to serve its webpages, which means that any webserver that implements a Rack handler can be used. This includes WEBrick, Mongrel, Thin, and Phusion Passenger (to name a few!).
NOTE: For more details on the Rack integration, see "Rails on Rack":rails_on_rack.html.
-To use a different server, just install its gem, then use its name for the first parameter to +rails server+:
+To use a different server, just install its gem, then use its name for the first parameter to `rails server`:
```bash
$ sudo gem install mongrel