change shell to bash

This commit is contained in:
Prem Sichanugrist 2012-09-01 20:45:26 -04:00 committed by Prem Sichanugrist
parent c89c163a0e
commit 21a0b20e39
20 changed files with 226 additions and 226 deletions

View File

@ -746,7 +746,7 @@ NOTE: Configuration files are not reloaded on each request, so you have to resta
Now the user can request to get a PDF version of a client just by adding ".pdf" to the URL: Now the user can request to get a PDF version of a client just by adding ".pdf" to the URL:
```shell ```bash
GET /clients/1.pdf GET /clients/1.pdf
``` ```

View File

@ -21,7 +21,7 @@ This section will provide a step-by-step guide to creating a mailer and its view
#### Create the Mailer #### Create the Mailer
```shell ```bash
$ rails generate mailer UserMailer $ rails generate mailer UserMailer
create app/mailers/user_mailer.rb create app/mailers/user_mailer.rb
invoke erb invoke erb
@ -111,7 +111,7 @@ Setting this up is painfully simple.
First off, we need to create a simple `User` scaffold: First off, we need to create a simple `User` scaffold:
```shell ```bash
$ rails generate scaffold user name:string email:string login:string $ rails generate scaffold user name:string email:string login:string
$ rake db:migrate $ rake db:migrate
``` ```

View File

@ -27,7 +27,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: Let's take a look at what Rails does by default when creating a new resource using the scaffold generator:
```shell ```bash
$ rails generate scaffold post $ rails generate scaffold post
[...] [...]
invoke scaffold_controller invoke scaffold_controller
@ -53,7 +53,7 @@ Action View works well with Action Record, but it can also be used with other Ru
Let's start by ensuring that you have the Action Pack and Rack gems installed: Let's start by ensuring that you have the Action Pack and Rack gems installed:
```shell ```bash
$ gem install actionpack $ gem install actionpack
$ gem install rack $ gem install rack
``` ```
@ -75,7 +75,7 @@ Rack::Handler::Mongrel.run method(:hello_world), :Port => 4567
We can see this all come together by starting up the application and then visiting +http://localhost:4567/+ We can see this all come together by starting up the application and then visiting +http://localhost:4567/+
```shell ```bash
$ ruby hello_world.rb $ ruby hello_world.rb
``` ```
@ -87,7 +87,7 @@ Action View can also be used with "Sinatra":http://www.sinatrarb.com/ in the sam
Let's start by ensuring that you have the Action Pack and Sinatra gems installed: Let's start by ensuring that you have the Action Pack and Sinatra gems installed:
```shell ```bash
$ gem install actionpack $ gem install actionpack
$ gem install sinatra $ gem install sinatra
``` ```
@ -107,7 +107,7 @@ end
Then, we can run the application: Then, we can run the application:
```shell ```bash
$ ruby hello_world.rb $ ruby hello_world.rb
``` ```

View File

@ -564,7 +564,7 @@ SELECT viewable_by, locked FROM clients
Be careful because this also means you're initializing a model object with only the fields that you've selected. If you attempt to access a field that is not in the initialized record you'll receive: Be careful because this also means you're initializing a model object with only the fields that you've selected. If you attempt to access a field that is not in the initialized record you'll receive:
```shell ```bash
ActiveModel::MissingAttributeError: missing attribute: <attribute> ActiveModel::MissingAttributeError: missing attribute: <attribute>
``` ```

View File

@ -1252,7 +1252,7 @@ Observers are similar to callbacks, but with important differences. Whereas call
For example, imagine a +User+ model where we want to send an email every time a new user is created. Because sending emails is not directly related to our model's purpose, we should create an observer to contain the code implementing this functionality. For example, imagine a +User+ model where we want to send an email every time a new user is created. Because sending emails is not directly related to our model's purpose, we should create an observer to contain the code implementing this functionality.
```shell ```bash
$ rails generate observer User $ rails generate observer User
``` ```

View File

@ -85,7 +85,7 @@ By default, +:defaults+ loads jQuery.
You can also choose to use Prototype instead of jQuery and specify the option You can also choose to use Prototype instead of jQuery and specify the option
using +-j+ switch while generating the application. using +-j+ switch while generating the application.
```shell ```bash
rails new app_name -j prototype rails new app_name -j prototype
``` ```

View File

@ -35,7 +35,7 @@ The first thing we'll want to do is create a new Rails application by running th
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.
```shell ```bash
$ rails new commandsapp $ rails new commandsapp
create create
create README.rdoc create README.rdoc
@ -60,7 +60,7 @@ INFO: WEBrick isn't your only option for serving Rails. We'll get to that "later
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:
```shell ```bash
$ cd commandsapp $ cd commandsapp
$ rails server $ rails server
=> Booting WEBrick => Booting WEBrick
@ -78,7 +78,7 @@ 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+.
```shell ```bash
$ rails server -e production -p 4000 $ rails server -e production -p 4000
``` ```
@ -90,7 +90,7 @@ The +rails generate+ command uses templates to create a whole lot of things. Run
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: `rails g`.
```shell ```bash
$ rails generate $ rails generate
Usage: rails generate GENERATOR [args] [options] Usage: rails generate GENERATOR [args] [options]
@ -115,7 +115,7 @@ 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+. 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+.
```shell ```bash
$ rails generate controller $ rails generate controller
Usage: rails generate controller NAME [action action] [options] Usage: rails generate controller NAME [action action] [options]
@ -142,7 +142,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. 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.
```shell ```bash
$ rails generate controller Greetings hello $ rails generate controller Greetings hello
create app/controllers/greetings_controller.rb create app/controllers/greetings_controller.rb
route get "greetings/hello" route get "greetings/hello"
@ -183,7 +183,7 @@ Then the view, to display our message (in +app/views/greetings/hello.html.erb+):
Fire up your server using +rails server+. Fire up your server using +rails server+.
```shell ```bash
$ rails server $ rails server
=> Booting WEBrick... => Booting WEBrick...
``` ```
@ -194,7 +194,7 @@ INFO: With a normal, plain-old Rails application, your URLs will generally follo
Rails comes with a generator for data models too. Rails comes with a generator for data models too.
```shell ```bash
$ rails generate model $ rails generate model
Usage: Usage:
rails generate model NAME [field[:type][:index] field[:type][:index]] [options] rails generate model NAME [field[:type][:index] field[:type][:index]] [options]
@ -217,7 +217,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. We will set up a simple resource called "HighScore" that will keep track of our highest score on video games we play.
```shell ```bash
$ rails generate scaffold HighScore game:string score:integer $ rails generate scaffold HighScore game:string score:integer
invoke active_record invoke active_record
create db/migrate/20120528060026_create_high_scores.rb create db/migrate/20120528060026_create_high_scores.rb
@ -254,7 +254,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 +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.
```shell ```bash
$ rake db:migrate $ rake db:migrate
== CreateHighScores: migrating =============================================== == CreateHighScores: migrating ===============================================
-- create_table(:high_scores) -- create_table(:high_scores)
@ -266,7 +266,7 @@ INFO: Let's talk about unit tests. Unit tests are code that tests and makes asse
Let's see the interface Rails created for us. Let's see the interface Rails created for us.
```shell ```bash
$ rails server $ rails server
``` ```
@ -280,13 +280,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. You can specify the environment in which the +console+ command should operate.
```shell ```bash
$ rails console staging $ 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+.
```shell ```bash
$ rails console --sandbox $ rails console --sandbox
Loading development environment in sandbox (Rails 3.2.3) Loading development environment in sandbox (Rails 3.2.3)
Any modifications you make will be rolled back on exit Any modifications you make will be rolled back on exit
@ -303,7 +303,7 @@ INFO: You can also use the alias "db" to invoke the dbconsole: `rails db`.
`runner` runs Ruby code in the context of Rails non-interactively. For instance: `runner` runs Ruby code in the context of Rails non-interactively. For instance:
```shell ```bash
$ rails runner "Model.long_running_method" $ rails runner "Model.long_running_method"
``` ```
@ -311,7 +311,7 @@ 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.
```shell ```bash
$ rails runner -e staging "Model.long_running_method" $ rails runner -e staging "Model.long_running_method"
``` ```
@ -321,7 +321,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`. INFO: You can also use the alias "d" to invoke the destroy command: `rails d`.
```shell ```bash
$ rails generate model Oops $ rails generate model Oops
invoke active_record invoke active_record
create db/migrate/20120528062523_create_oops.rb create db/migrate/20120528062523_create_oops.rb
@ -330,7 +330,7 @@ $ rails generate model Oops
create test/unit/oops_test.rb create test/unit/oops_test.rb
create test/fixtures/oops.yml create test/fixtures/oops.yml
``` ```
```shell ```bash
$ rails destroy model Oops $ rails destroy model Oops
invoke active_record invoke active_record
remove db/migrate/20120528062523_create_oops.rb remove db/migrate/20120528062523_create_oops.rb
@ -347,7 +347,7 @@ Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'mak
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.
```shell ```bash
$ rake --tasks $ rake --tasks
rake about # List versions of all Rails frameworks and the environment rake about # List versions of all Rails frameworks and the environment
rake assets:clean # Remove compiled assets rake assets:clean # Remove compiled assets
@ -365,7 +365,7 @@ rake tmp:create # Creates tmp directories for sessions, cache, sockets,
`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. `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.
```shell ```bash
$ rake about $ rake about
About your application's environment About your application's environment
Ruby version 1.9.3 (x86_64-linux) Ruby version 1.9.3 (x86_64-linux)
@ -406,7 +406,7 @@ The +doc:+ namespace has the tools to generate documentation for your app, API d
+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.
```shell ```bash
$ rake notes $ rake notes
(in /home/foobar/commandsapp) (in /home/foobar/commandsapp)
app/controllers/admin/users_controller.rb: app/controllers/admin/users_controller.rb:
@ -420,7 +420,7 @@ app/model/school.rb:
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.
```shell ```bash
$ rake notes:fixme $ rake notes:fixme
(in /home/foobar/commandsapp) (in /home/foobar/commandsapp)
app/controllers/admin/users_controller.rb: app/controllers/admin/users_controller.rb:
@ -432,7 +432,7 @@ app/model/school.rb:
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+.
```shell ```bash
$ rake notes:custom ANNOTATION=BUG $ rake notes:custom ANNOTATION=BUG
(in /home/foobar/commandsapp) (in /home/foobar/commandsapp)
app/model/post.rb: app/model/post.rb:
@ -443,7 +443,7 @@ NOTE. When using specific annotations and custom annotations, the annotation nam
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+.
```shell ```bash
$ export SOURCE_ANNOTATION_DIRECTORIES='rspec,vendor' $ export SOURCE_ANNOTATION_DIRECTORIES='rspec,vendor'
$ rake notes $ rake notes
(in /home/foobar/commandsapp) (in /home/foobar/commandsapp)
@ -519,7 +519,7 @@ end
You can see your tasks to be listed by `rake -T` command. And, according to the examples above, you can invoke them as follows: You can see your tasks to be listed by `rake -T` command. And, according to the examples above, you can invoke them as follows:
```shell ```bash
rake task_name rake task_name
rake "task_name[value 1]" # entire argument string should be quoted rake "task_name[value 1]" # entire argument string should be quoted
rake do:nothing rake do:nothing
@ -538,7 +538,7 @@ When creating a new Rails application, you have the option to specify what kind
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:
```shell ```bash
$ mkdir gitapp $ mkdir gitapp
$ cd gitapp $ cd gitapp
$ git init $ git init
@ -565,7 +565,7 @@ add 'log/test.log'
We had to create the *gitapp* directory and initialize an empty git repository before Rails would add files it created to our repository. Let's see what it put in our database configuration: We had to create the *gitapp* directory and initialize an empty git repository before Rails would add files it created to our repository. Let's see what it put in our database configuration:
```shell ```bash
$ cat config/database.yml $ cat config/database.yml
# PostgreSQL. Versions 8.2 and up are supported. # PostgreSQL. Versions 8.2 and up are supported.
# #
@ -600,7 +600,7 @@ NOTE: For more details on the Rack integration, see "Rails on Rack":rails_on_rac
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+:
```shell ```bash
$ sudo gem install mongrel $ sudo gem install mongrel
Building native extensions. This could take a while... Building native extensions. This could take a while...
Building native extensions. This could take a while... Building native extensions. This could take a while...

View File

@ -62,7 +62,7 @@ Ruby on Rails uses Git for source code control. The "Git homepage":http://git-sc
Navigate to the folder where you want the Ruby on Rails source code (it will create its own +rails+ subdirectory) and run: Navigate to the folder where you want the Ruby on Rails source code (it will create its own +rails+ subdirectory) and run:
```shell ```bash
$ git clone git://github.com/rails/rails.git $ git clone git://github.com/rails/rails.git
$ cd rails $ cd rails
``` ```
@ -73,13 +73,13 @@ The test suite must pass with any submitted code. No matter whether you are writ
Install first libxml2 and libxslt together with their development files for Nokogiri. In Ubuntu that's Install first libxml2 and libxslt together with their development files for Nokogiri. In Ubuntu that's
```shell ```bash
$ sudo apt-get install libxml2 libxml2-dev libxslt1-dev $ sudo apt-get install libxml2 libxml2-dev libxslt1-dev
``` ```
If you are on Fedora or CentOS, you can run If you are on Fedora or CentOS, you can run
```shell ```bash
$ sudo yum install libxml2 libxml2-devel libxslt libxslt-devel $ sudo yum install libxml2 libxml2-devel libxslt libxslt-devel
``` ```
@ -87,52 +87,52 @@ If you have any problems with these libraries, you should install them manually
Also, SQLite3 and its development files for the +sqlite3-ruby+ gem -- in Ubuntu you're done with just Also, SQLite3 and its development files for the +sqlite3-ruby+ gem -- in Ubuntu you're done with just
```shell ```bash
$ sudo apt-get install sqlite3 libsqlite3-dev $ sudo apt-get install sqlite3 libsqlite3-dev
``` ```
And if you are on Fedora or CentOS, you're done with And if you are on Fedora or CentOS, you're done with
```shell ```bash
$ sudo yum install sqlite3 sqlite3-devel $ sudo yum install sqlite3 sqlite3-devel
``` ```
Get a recent version of "Bundler":http://gembundler.com/: Get a recent version of "Bundler":http://gembundler.com/:
```shell ```bash
$ gem install bundler $ gem install bundler
$ gem update bundler $ gem update bundler
``` ```
and run: and run:
```shell ```bash
$ bundle install --without db $ bundle install --without db
``` ```
This command will install all dependencies except the MySQL and PostgreSQL Ruby drivers. We will come back to these soon. With dependencies installed, you can run the test suite with: This command will install all dependencies except the MySQL and PostgreSQL Ruby drivers. We will come back to these soon. With dependencies installed, you can run the test suite with:
```shell ```bash
$ bundle exec rake test $ bundle exec rake test
``` ```
You can also run tests for a specific component, like Action Pack, by going into its directory and executing the same command: You can also run tests for a specific component, like Action Pack, by going into its directory and executing the same command:
```shell ```bash
$ cd actionpack $ cd actionpack
$ bundle exec rake test $ bundle exec rake test
``` ```
If you want to run the tests located in a specific directory use the +TEST_DIR+ environment variable. For example, this will run the tests of the +railties/test/generators+ directory only: If you want to run the tests located in a specific directory use the +TEST_DIR+ environment variable. For example, this will run the tests of the +railties/test/generators+ directory only:
```shell ```bash
$ cd railties $ cd railties
$ TEST_DIR=generators bundle exec rake test $ TEST_DIR=generators bundle exec rake test
``` ```
You can run any single test separately too: You can run any single test separately too:
```shell ```bash
$ cd actionpack $ cd actionpack
$ bundle exec ruby -Itest test/template/form_helper_test.rb $ bundle exec ruby -Itest test/template/form_helper_test.rb
``` ```
@ -151,21 +151,21 @@ The Active Record test suite requires a custom config file: +activerecord/test/c
To be able to run the suite for MySQL and PostgreSQL we need their gems. Install first the servers, their client libraries, and their development files. In Ubuntu just run To be able to run the suite for MySQL and PostgreSQL we need their gems. Install first the servers, their client libraries, and their development files. In Ubuntu just run
```shell ```bash
$ sudo apt-get install mysql-server libmysqlclient15-dev $ sudo apt-get install mysql-server libmysqlclient15-dev
$ sudo apt-get install postgresql postgresql-client postgresql-contrib libpq-dev $ sudo apt-get install postgresql postgresql-client postgresql-contrib libpq-dev
``` ```
On Fedora or CentOS, just run: On Fedora or CentOS, just run:
```shell ```bash
$ sudo yum install mysql-server mysql-devel $ sudo yum install mysql-server mysql-devel
$ sudo yum install postgresql-server postgresql-devel $ sudo yum install postgresql-server postgresql-devel
``` ```
After that run: After that run:
```shell ```bash
$ rm .bundle/config $ rm .bundle/config
$ bundle install $ bundle install
``` ```
@ -174,7 +174,7 @@ We need first to delete +.bundle/config+ because Bundler remembers in that file
In order to be able to run the test suite against MySQL you need to create a user named +rails+ with privileges on the test databases: In order to be able to run the test suite against MySQL you need to create a user named +rails+ with privileges on the test databases:
```shell ```bash
mysql> GRANT ALL PRIVILEGES ON activerecord_unittest.* mysql> GRANT ALL PRIVILEGES ON activerecord_unittest.*
to 'rails'@'localhost'; to 'rails'@'localhost';
mysql> GRANT ALL PRIVILEGES ON activerecord_unittest2.* mysql> GRANT ALL PRIVILEGES ON activerecord_unittest2.*
@ -183,20 +183,20 @@ mysql> GRANT ALL PRIVILEGES ON activerecord_unittest2.*
and create the test databases: and create the test databases:
```shell ```bash
$ cd activerecord $ cd activerecord
$ bundle exec rake mysql:build_databases $ bundle exec rake mysql:build_databases
``` ```
PostgreSQL's authentication works differently. A simple way to set up the development environment for example is to run with your development account PostgreSQL's authentication works differently. A simple way to set up the development environment for example is to run with your development account
```shell ```bash
$ sudo -u postgres createuser --superuser $USER $ sudo -u postgres createuser --superuser $USER
``` ```
and then create the test databases with and then create the test databases with
```shell ```bash
$ cd activerecord $ cd activerecord
$ bundle exec rake postgresql:build_databases $ bundle exec rake postgresql:build_databases
``` ```
@ -212,14 +212,14 @@ Testing Active Record
This is how you run the Active Record test suite only for SQLite3: This is how you run the Active Record test suite only for SQLite3:
```shell ```bash
$ cd activerecord $ cd activerecord
$ bundle exec rake test_sqlite3 $ bundle exec rake test_sqlite3
``` ```
You can now run the tests as you did for +sqlite3+. The tasks are respectively You can now run the tests as you did for +sqlite3+. The tasks are respectively
```shell ```bash
test_mysql test_mysql
test_mysql2 test_mysql2
test_postgresql test_postgresql
@ -227,7 +227,7 @@ test_postgresql
Finally, Finally,
```shell ```bash
$ bundle exec rake test $ bundle exec rake test
``` ```
@ -235,7 +235,7 @@ will now run the four of them in turn.
You can also run any single test separately: You can also run any single test separately:
```shell ```bash
$ ARCONN=sqlite3 ruby -Itest test/cases/associations/has_many_associations_test.rb $ ARCONN=sqlite3 ruby -Itest test/cases/associations/has_many_associations_test.rb
``` ```
@ -247,7 +247,7 @@ The test suite runs with warnings enabled. Ideally, Ruby on Rails should issue n
As of this writing (December, 2010) they are specially noisy with Ruby 1.9. If you are sure about what you are doing and would like to have a more clear output, there's a way to override the flag: As of this writing (December, 2010) they are specially noisy with Ruby 1.9. If you are sure about what you are doing and would like to have a more clear output, there's a way to override the flag:
```shell ```bash
$ RUBYOPT=-W0 bundle exec rake test $ RUBYOPT=-W0 bundle exec rake test
``` ```
@ -255,7 +255,7 @@ $ RUBYOPT=-W0 bundle exec rake test
If you want to add a fix to older versions of Ruby on Rails, you'll need to set up and switch to your own local tracking branch. Here is an example to switch to the 3-0-stable branch: If you want to add a fix to older versions of Ruby on Rails, you'll need to set up and switch to your own local tracking branch. Here is an example to switch to the 3-0-stable branch:
```shell ```bash
$ git branch --track 3-0-stable origin/3-0-stable $ git branch --track 3-0-stable origin/3-0-stable
$ git checkout 3-0-stable $ git checkout 3-0-stable
``` ```
@ -281,13 +281,13 @@ Anything you can do to make bug reports more succinct or easier to reproduce is
You can also help out by examining pull requests that have been submitted to Ruby on Rails via GitHub. To apply someone's changes you need first to create a dedicated branch: You can also help out by examining pull requests that have been submitted to Ruby on Rails via GitHub. To apply someone's changes you need first to create a dedicated branch:
```shell ```bash
$ git checkout -b testing_branch $ git checkout -b testing_branch
``` ```
Then you can use their remote branch to update your codebase. For example, let's say the GitHub user JohnSmith has forked and pushed to a topic branch "orange" located at https://github.com/JohnSmith/rails. Then you can use their remote branch to update your codebase. For example, let's say the GitHub user JohnSmith has forked and pushed to a topic branch "orange" located at https://github.com/JohnSmith/rails.
```shell ```bash
$ git remote add JohnSmith git://github.com/JohnSmith/rails.git $ git remote add JohnSmith git://github.com/JohnSmith/rails.git
$ git pull JohnSmith orange $ git pull JohnSmith orange
``` ```
@ -333,13 +333,13 @@ Contributing to the Rails Code
The first thing you need to do to be able to contribute code is to clone the repository: The first thing you need to do to be able to contribute code is to clone the repository:
```shell ```bash
$ git clone git://github.com/rails/rails.git $ git clone git://github.com/rails/rails.git
``` ```
and create a dedicated branch: and create a dedicated branch:
```shell ```bash
$ cd rails $ cd rails
$ git checkout -b my_new_branch $ git checkout -b my_new_branch
``` ```
@ -407,7 +407,7 @@ You might want also to check out the "RailsBridge BugMash":http://wiki.railsbrid
When you're happy with the code on your computer, you need to commit the changes to Git: When you're happy with the code on your computer, you need to commit the changes to Git:
```shell ```bash
$ git commit -a $ git commit -a
``` ```
@ -447,14 +447,14 @@ TIP. Please squash your commits into a single commit when appropriate. This simp
Its pretty likely that other changes to master have happened while you were working. Go get them: Its pretty likely that other changes to master have happened while you were working. Go get them:
```shell ```bash
$ git checkout master $ git checkout master
$ git pull --rebase $ git pull --rebase
``` ```
Now reapply your patch on top of the latest changes: Now reapply your patch on top of the latest changes:
```shell ```bash
$ git checkout my_new_branch $ git checkout my_new_branch
$ git rebase master $ git rebase master
``` ```
@ -467,13 +467,13 @@ Navigate to the Rails "GitHub repository":https://github.com/rails/rails and pre
Add the new remote to your local repository on your local machine: Add the new remote to your local repository on your local machine:
```shell ```bash
$ git remote add mine git@github.com:<your user name>/rails.git $ git remote add mine git@github.com:<your user name>/rails.git
``` ```
Push to your remote: Push to your remote:
```shell ```bash
$ git push mine my_new_branch $ git push mine my_new_branch
``` ```
@ -481,32 +481,32 @@ You might have cloned your forked repository into your machine and might want to
In the directory you cloned your fork: In the directory you cloned your fork:
```shell ```bash
$ git remote add rails git://github.com/rails/rails.git $ git remote add rails git://github.com/rails/rails.git
``` ```
Download new commits and branches from the official repository: Download new commits and branches from the official repository:
```shell ```bash
$ git fetch rails $ git fetch rails
``` ```
Merge the new content: Merge the new content:
```shell ```bash
$ git checkout master $ git checkout master
$ git rebase rails/master $ git rebase rails/master
``` ```
Update your fork: Update your fork:
```shell ```bash
$ git push origin master $ git push origin master
``` ```
If you want to update another branches: If you want to update another branches:
```shell ```bash
$ git checkout branch_name $ git checkout branch_name
$ git rebase rails/branch_name $ git rebase rails/branch_name
$ git push origin branch_name $ git push origin branch_name
@ -539,19 +539,19 @@ For simple fixes, the easiest way to backport your changes is to "extract a diff
First make sure your changes are the only difference between your current branch and master: First make sure your changes are the only difference between your current branch and master:
```shell ```bash
$ git log master..HEAD $ git log master..HEAD
``` ```
Then extract the diff: Then extract the diff:
```shell ```bash
$ git format-patch master --stdout > ~/my_changes.patch $ git format-patch master --stdout > ~/my_changes.patch
``` ```
Switch over to the target branch and apply your changes: Switch over to the target branch and apply your changes:
```shell ```bash
$ git checkout -b my_backport_branch 3-2-stable $ git checkout -b my_backport_branch 3-2-stable
$ git apply ~/my_changes.patch $ git apply ~/my_changes.patch
``` ```

View File

@ -174,7 +174,7 @@ end
Here's an example of the log generated by this method: Here's an example of the log generated by this method:
```shell ```bash
Processing PostsController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST] Processing PostsController#create (for 127.0.0.1 at 2008-09-08 11:52:54) [POST]
Session ID: BAh7BzoMY3NyZl9pZCIlMDY5MWU1M2I1ZDRjODBlMzkyMWI1OTg2NWQyNzViZjYiCmZsYXNoSUM6J0FjdGl Session ID: BAh7BzoMY3NyZl9pZCIlMDY5MWU1M2I1ZDRjODBlMzkyMWI1OTg2NWQyNzViZjYiCmZsYXNoSUM6J0FjdGl
vbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--b18cd92fba90eacf8137e5f6b3b06c4d724596a4 vbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--b18cd92fba90eacf8137e5f6b3b06c4d724596a4
@ -216,7 +216,7 @@ The debugger can also help you if you want to learn about the Rails source code
Rails uses the +debugger+ gem to set breakpoints and step through live code. To install it, just run: Rails uses the +debugger+ gem to set breakpoints and step through live code. To install it, just run:
```shell ```bash
$ gem install debugger $ gem install debugger
``` ```
@ -235,13 +235,13 @@ end
If you see the message in the console or logs: If you see the message in the console or logs:
```shell ```bash
***** Debugger requested, but was not available: Start server with --debugger to enable ***** ***** Debugger requested, but was not available: Start server with --debugger to enable *****
``` ```
Make sure you have started your web server with the option +--debugger+: Make sure you have started your web server with the option +--debugger+:
```shell ```bash
$ rails server --debugger $ rails server --debugger
=> Booting WEBrick => Booting WEBrick
=> Rails 3.0.0 application starting on http://0.0.0.0:3000 => Rails 3.0.0 application starting on http://0.0.0.0:3000
@ -259,14 +259,14 @@ If you got there by a browser request, the browser tab containing the request wi
For example: For example:
```shell ```bash
@posts = Post.all @posts = Post.all
(rdb:7) (rdb:7)
``` ```
Now it's time to explore and dig into your application. A good place to start is by asking the debugger for help... so type: +help+ (You didn't see that coming, right?) Now it's time to explore and dig into your application. A good place to start is by asking the debugger for help... so type: +help+ (You didn't see that coming, right?)
```shell ```bash
(rdb:7) help (rdb:7) help
ruby-debug help v0.10.2 ruby-debug help v0.10.2
Type 'help <command-name>' for help on a specific command Type 'help <command-name>' for help on a specific command
@ -285,7 +285,7 @@ The next command to learn is one of the most useful: +list+. You can abbreviate
This command shows you where you are in the code by printing 10 lines centered around the current line; the current line in this particular case is line 6 and is marked by +=>+. This command shows you where you are in the code by printing 10 lines centered around the current line; the current line in this particular case is line 6 and is marked by +=>+.
```shell ```bash
(rdb:7) list (rdb:7) list
[1, 10] in /PathToProject/posts_controller.rb [1, 10] in /PathToProject/posts_controller.rb
1 class PostsController < ApplicationController 1 class PostsController < ApplicationController
@ -302,7 +302,7 @@ This command shows you where you are in the code by printing 10 lines centered a
If you repeat the +list+ command, this time using just +l+, the next ten lines of the file will be printed out. If you repeat the +list+ command, this time using just +l+, the next ten lines of the file will be printed out.
```shell ```bash
(rdb:7) l (rdb:7) l
[11, 20] in /PathTo/project/app/controllers/posts_controller.rb [11, 20] in /PathTo/project/app/controllers/posts_controller.rb
11 end 11 end
@ -321,7 +321,7 @@ And so on until the end of the current file. When the end of file is reached, th
On the other hand, to see the previous ten lines you should type +list-+ (or +l-+) On the other hand, to see the previous ten lines you should type +list-+ (or +l-+)
```shell ```bash
(rdb:7) l- (rdb:7) l-
[1, 10] in /PathToProject/posts_controller.rb [1, 10] in /PathToProject/posts_controller.rb
1 class PostsController < ApplicationController 1 class PostsController < ApplicationController
@ -339,7 +339,7 @@ On the other hand, to see the previous ten lines you should type +list-+ (or +l-
This way you can move inside the file, being able to see the code above and over the line you added the +debugger+. This way you can move inside the file, being able to see the code above and over the line you added the +debugger+.
Finally, to see where you are in the code again you can type +list=+ Finally, to see where you are in the code again you can type +list=+
```shell ```bash
(rdb:7) list= (rdb:7) list=
[1, 10] in /PathToProject/posts_controller.rb [1, 10] in /PathToProject/posts_controller.rb
1 class PostsController < ApplicationController 1 class PostsController < ApplicationController
@ -362,7 +362,7 @@ The debugger creates a context when a stopping point or an event is reached. The
At any time you can call the +backtrace+ command (or its alias +where+) to print the backtrace of the application. This can be very helpful to know how you got where you are. If you ever wondered about how you got somewhere in your code, then +backtrace+ will supply the answer. At any time you can call the +backtrace+ command (or its alias +where+) to print the backtrace of the application. This can be very helpful to know how you got where you are. If you ever wondered about how you got somewhere in your code, then +backtrace+ will supply the answer.
```shell ```bash
(rdb:5) where (rdb:5) where
#0 PostsController.index #0 PostsController.index
at line /PathTo/project/app/controllers/posts_controller.rb:6 at line /PathTo/project/app/controllers/posts_controller.rb:6
@ -377,7 +377,7 @@ At any time you can call the +backtrace+ command (or its alias +where+) to print
You move anywhere you want in this trace (thus changing the context) by using the +frame _n_+ command, where _n_ is the specified frame number. You move anywhere you want in this trace (thus changing the context) by using the +frame _n_+ command, where _n_ is the specified frame number.
```shell ```bash
(rdb:5) frame 2 (rdb:5) frame 2
#2 ActionController::Base.perform_action_without_filters #2 ActionController::Base.perform_action_without_filters
at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175 at line /PathTo/project/vendor/rails/actionpack/lib/action_controller/base.rb:1175
@ -405,7 +405,7 @@ Any expression can be evaluated in the current context. To evaluate an expressio
This example shows how you can print the instance_variables defined within the current context: This example shows how you can print the instance_variables defined within the current context:
```shell ```bash
@posts = Post.all @posts = Post.all
(rdb:11) instance_variables (rdb:11) instance_variables
["@_response", "@action_name", "@url", "@_session", "@_cookies", "@performed_render", "@_flash", "@template", "@_params", "@before_filter_chain_aborted", "@request_origin", "@_headers", "@performed_redirect", "@_request"] ["@_response", "@action_name", "@url", "@_session", "@_cookies", "@performed_render", "@_flash", "@template", "@_params", "@before_filter_chain_aborted", "@request_origin", "@_headers", "@performed_redirect", "@_request"]
@ -413,7 +413,7 @@ This example shows how you can print the instance_variables defined within the c
As you may have figured out, all of the variables that you can access from a controller are displayed. This list is dynamically updated as you execute code. For example, run the next line using +next+ (you'll learn more about this command later in this guide). As you may have figured out, all of the variables that you can access from a controller are displayed. This list is dynamically updated as you execute code. For example, run the next line using +next+ (you'll learn more about this command later in this guide).
```shell ```bash
(rdb:11) next (rdb:11) next
Processing PostsController#index (for 127.0.0.1 at 2008-09-04 19:51:34) [GET] Processing PostsController#index (for 127.0.0.1 at 2008-09-04 19:51:34) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==--b16e91b992453a8cc201694d660147bba8b0fd0e Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==--b16e91b992453a8cc201694d660147bba8b0fd0e
@ -424,7 +424,7 @@ respond_to do |format|
And then ask again for the instance_variables: And then ask again for the instance_variables:
```shell ```bash
(rdb:11) instance_variables.include? "@posts" (rdb:11) instance_variables.include? "@posts"
true true
``` ```
@ -435,7 +435,7 @@ TIP: You can also step into *irb* mode with the command +irb+ (of course!). This
The +var+ method is the most convenient way to show variables and their values: The +var+ method is the most convenient way to show variables and their values:
```shell ```bash
var var
(rdb:1) v[ar] const <object> show constants of object (rdb:1) v[ar] const <object> show constants of object
(rdb:1) v[ar] g[lobal] show global variables (rdb:1) v[ar] g[lobal] show global variables
@ -445,14 +445,14 @@ var
This is a great way to inspect the values of the current context variables. For example: This is a great way to inspect the values of the current context variables. For example:
```shell ```bash
(rdb:9) var local (rdb:9) var local
__dbg_verbose_save => false __dbg_verbose_save => false
``` ```
You can also inspect for an object method this way: You can also inspect for an object method this way:
```shell ```bash
(rdb:9) var instance Post.new (rdb:9) var instance Post.new
@attributes = {"updated_at"=>nil, "body"=>nil, "title"=>nil, "published"=>nil, "created_at"... @attributes = {"updated_at"=>nil, "body"=>nil, "title"=>nil, "published"=>nil, "created_at"...
@attributes_cache = {} @attributes_cache = {}
@ -463,7 +463,7 @@ TIP: The commands +p+ (print) and +pp+ (pretty print) can be used to evaluate Ru
You can use also +display+ to start watching variables. This is a good way of tracking the values of a variable while the execution goes on. You can use also +display+ to start watching variables. This is a good way of tracking the values of a variable while the execution goes on.
```shell ```bash
(rdb:1) display @recent_comments (rdb:1) display @recent_comments
1: @recent_comments = 1: @recent_comments =
``` ```
@ -498,7 +498,7 @@ end
TIP: You can use the debugger while using +rails console+. Just remember to +require "debugger"+ before calling the +debugger+ method. TIP: You can use the debugger while using +rails console+. Just remember to +require "debugger"+ before calling the +debugger+ method.
```shell ```bash
$ rails console $ rails console
Loading development environment (Rails 3.1.0) Loading development environment (Rails 3.1.0)
>> require "debugger" >> require "debugger"
@ -512,7 +512,7 @@ Loading development environment (Rails 3.1.0)
With the code stopped, take a look around: With the code stopped, take a look around:
```shell ```bash
(rdb:1) list (rdb:1) list
[2, 9] in /PathTo/project/app/models/author.rb [2, 9] in /PathTo/project/app/models/author.rb
2 has_one :editorial 2 has_one :editorial
@ -527,7 +527,7 @@ With the code stopped, take a look around:
You are at the end of the line, but... was this line executed? You can inspect the instance variables. You are at the end of the line, but... was this line executed? You can inspect the instance variables.
```shell ```bash
(rdb:1) var instance (rdb:1) var instance
@attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las... @attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las...
@attributes_cache = {} @attributes_cache = {}
@ -535,7 +535,7 @@ You are at the end of the line, but... was this line executed? You can inspect t
+@recent_comments+ hasn't been defined yet, so it's clear that this line hasn't been executed yet. Use the +next+ command to move on in the code: +@recent_comments+ hasn't been defined yet, so it's clear that this line hasn't been executed yet. Use the +next+ command to move on in the code:
```shell ```bash
(rdb:1) next (rdb:1) next
/PathTo/project/app/models/author.rb:12 /PathTo/project/app/models/author.rb:12
@recent_comments @recent_comments
@ -560,14 +560,14 @@ You can add breakpoints dynamically with the command +break+ (or just +b+). Ther
* +break file:line [if expression]+: set breakpoint in the _line_ number inside the _file_. If an _expression_ is given it must evaluated to _true_ to fire up the debugger. * +break file:line [if expression]+: set breakpoint in the _line_ number inside the _file_. If an _expression_ is given it must evaluated to _true_ to fire up the debugger.
* +break class(.|\#)method [if expression]+: set breakpoint in _method_ (. and \# for class and instance method respectively) defined in _class_. The _expression_ works the same way as with file:line. * +break class(.|\#)method [if expression]+: set breakpoint in _method_ (. and \# for class and instance method respectively) defined in _class_. The _expression_ works the same way as with file:line.
```shell ```bash
(rdb:5) break 10 (rdb:5) break 10
Breakpoint 1 file /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb, line 10 Breakpoint 1 file /PathTo/project/vendor/rails/actionpack/lib/action_controller/filters.rb, line 10
``` ```
Use +info breakpoints _n_+ or +info break _n_+ to list breakpoints. If you supply a number, it lists that breakpoint. Otherwise it lists all breakpoints. Use +info breakpoints _n_+ or +info break _n_+ to list breakpoints. If you supply a number, it lists that breakpoint. Otherwise it lists all breakpoints.
```shell ```bash
(rdb:5) info breakpoints (rdb:5) info breakpoints
Num Enb What Num Enb What
1 y at filters.rb:10 1 y at filters.rb:10
@ -575,7 +575,7 @@ Num Enb What
To delete breakpoints: use the command +delete _n_+ to remove the breakpoint number _n_. If no number is specified, it deletes all breakpoints that are currently active.. To delete breakpoints: use the command +delete _n_+ to remove the breakpoint number _n_. If no number is specified, it deletes all breakpoints that are currently active..
```shell ```bash
(rdb:5) delete 1 (rdb:5) delete 1
(rdb:5) info breakpoints (rdb:5) info breakpoints
No breakpoints. No breakpoints.
@ -627,7 +627,7 @@ TIP: You can save these settings in an +.rdebugrc+ file in your home directory.
Here's a good start for an +.rdebugrc+: Here's a good start for an +.rdebugrc+:
```shell ```bash
set autolist set autolist
set forcestep set forcestep
set listsize 25 set listsize 25
@ -648,7 +648,7 @@ If a Ruby object does not go out of scope, the Ruby Garbage Collector won't swee
To install it run: To install it run:
```shell ```bash
$ gem install bleak_house $ gem install bleak_house
``` ```
@ -660,13 +660,13 @@ require 'bleak_house' if ENV['BLEAK_HOUSE']
Start a server instance with BleakHouse integration: Start a server instance with BleakHouse integration:
```shell ```bash
$ RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house rails server $ RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house rails server
``` ```
Make sure to run a couple hundred requests to get better data samples, then press +CTRL-C+. The server will stop and Bleak House will produce a dumpfile in +/tmp+: Make sure to run a couple hundred requests to get better data samples, then press +CTRL-C+. The server will stop and Bleak House will produce a dumpfile in +/tmp+:
```shell ```bash
** BleakHouse: working... ** BleakHouse: working...
** BleakHouse: complete ** BleakHouse: complete
** Bleakhouse: run 'bleak /tmp/bleak.5979.0.dump' to analyze. ** Bleakhouse: run 'bleak /tmp/bleak.5979.0.dump' to analyze.
@ -674,7 +674,7 @@ Make sure to run a couple hundred requests to get better data samples, then pres
To analyze it, just run the listed command. The top 20 leakiest lines will be listed: To analyze it, just run the listed command. The top 20 leakiest lines will be listed:
```shell ```bash
191691 total objects 191691 total objects
Final heap size 191691 filled, 220961 free Final heap size 191691 filled, 220961 free
Displaying top 20 most common line/class pairs Displaying top 20 most common line/class pairs

View File

@ -35,13 +35,13 @@ Generating an engine
To generate an engine with Rails 3.1, you will need to run the plugin generator and pass it the +--full+ and +--mountable+ options. To generate the beginnings of the "blorgh" engine you will need to run this command in a terminal: To generate an engine with Rails 3.1, you will need to run the plugin generator and pass it the +--full+ and +--mountable+ options. To generate the beginnings of the "blorgh" engine you will need to run this command in a terminal:
```shell ```bash
$ rails plugin new blorgh --full --mountable $ rails plugin new blorgh --full --mountable
``` ```
The full list of options for the plugin generator may be seen by typing: The full list of options for the plugin generator may be seen by typing:
```shell ```bash
$ rails plugin --help $ rails plugin --help
``` ```
@ -112,7 +112,7 @@ If you don't want to force a layout on to users of the engine, then you can dele
This directory contains one file, +script/rails+, which enables you to use the +rails+ sub-commands and generators just like you would within an application. This means that you will very easily be able to generate new controllers and models for this engine by running commands like this: This directory contains one file, +script/rails+, which enables you to use the +rails+ sub-commands and generators just like you would within an application. This means that you will very easily be able to generate new controllers and models for this engine by running commands like this:
```shell ```bash
rails g model rails g model
``` ```
@ -141,13 +141,13 @@ The engine that this guide covers provides posting and commenting functionality
The first thing to generate for a blog engine is the +Post+ model and related controller. To quickly generate this, you can use the Rails scaffold generator. The first thing to generate for a blog engine is the +Post+ model and related controller. To quickly generate this, you can use the Rails scaffold generator.
```shell ```bash
$ rails generate scaffold post title:string text:text $ rails generate scaffold post title:string text:text
``` ```
This command will output this information: This command will output this information:
```shell ```bash
invoke active_record invoke active_record
create db/migrate/[timestamp]_create_blorgh_posts.rb create db/migrate/[timestamp]_create_blorgh_posts.rb
create app/models/blorgh/post.rb create app/models/blorgh/post.rb
@ -250,13 +250,13 @@ Now that the engine has the ability to create new blog posts, it only makes sens
Run the model generator and tell it to generate a +Comment+ model, with the related table having two columns: a +post_id+ integer and +text+ text column. Run the model generator and tell it to generate a +Comment+ model, with the related table having two columns: a +post_id+ integer and +text+ text column.
```shell ```bash
$ rails generate model Comment post_id:integer text:text $ rails generate model Comment post_id:integer text:text
``` ```
This will output the following: This will output the following:
```shell ```bash
invoke active_record invoke active_record
create db/migrate/[timestamp]_create_blorgh_comments.rb create db/migrate/[timestamp]_create_blorgh_comments.rb
create app/models/blorgh/comment.rb create app/models/blorgh/comment.rb
@ -323,13 +323,13 @@ This creates a nested route for the comments, which is what the form requires.
The route now exists, but the controller that this route goes to does not. To create it, run this command: The route now exists, but the controller that this route goes to does not. To create it, run this command:
```shell ```bash
$ rails g controller comments $ rails g controller comments
``` ```
This will generate the following things: This will generate the following things:
```shell ```bash
create app/controllers/blorgh/comments_controller.rb create app/controllers/blorgh/comments_controller.rb
invoke erb invoke erb
exist app/views/blorgh/comments exist app/views/blorgh/comments
@ -386,7 +386,7 @@ Using an engine within an application is very easy. This section covers how to m
First, the engine needs to be specified inside the application's +Gemfile+. If there isn't an application handy to test this out in, generate one using the +rails new+ command outside of the engine directory like this: First, the engine needs to be specified inside the application's +Gemfile+. If there isn't an application handy to test this out in, generate one using the +rails new+ command outside of the engine directory like this:
```shell ```bash
$ rails new unicorn $ rails new unicorn
``` ```
@ -418,19 +418,19 @@ NOTE: Other engines, such as Devise, handle this a little differently by making
The engine contains migrations for the +blorgh_posts+ and +blorgh_comments+ table which need to be created in the application's database so that the engine's models can query them correctly. To copy these migrations into the application use this command: The engine contains migrations for the +blorgh_posts+ and +blorgh_comments+ table which need to be created in the application's database so that the engine's models can query them correctly. To copy these migrations into the application use this command:
```shell ```bash
$ rake blorgh:install:migrations $ rake blorgh:install:migrations
``` ```
If you have multiple engines that need migrations copied over, use +railties:install:migrations+ instead: If you have multiple engines that need migrations copied over, use +railties:install:migrations+ instead:
```shell ```bash
$ rake railties:install:migrations $ rake railties:install:migrations
``` ```
This command, when run for the first time will copy over all the migrations from the engine. When run the next time, it will only copy over migrations that haven't been copied over already. The first run for this command will output something such as this: This command, when run for the first time will copy over all the migrations from the engine. When run the next time, it will only copy over migrations that haven't been copied over already. The first run for this command will output something such as this:
```shell ```bash
Copied migration [timestamp_1]_create_blorgh_posts.rb from blorgh Copied migration [timestamp_1]_create_blorgh_posts.rb from blorgh
Copied migration [timestamp_2]_create_blorgh_comments.rb from blorgh Copied migration [timestamp_2]_create_blorgh_comments.rb from blorgh
``` ```
@ -441,13 +441,13 @@ To run these migrations within the context of the application, simply run +rake
If you would like to run migrations only from one engine, you can do it by specifying +SCOPE+: If you would like to run migrations only from one engine, you can do it by specifying +SCOPE+:
```shell ```bash
rake db:migrate SCOPE=blorgh rake db:migrate SCOPE=blorgh
``` ```
This may be useful if you want to revert engine's migrations before removing it. In order to revert all migrations from blorgh engine you can run such code: This may be useful if you want to revert engine's migrations before removing it. In order to revert all migrations from blorgh engine you can run such code:
```shell ```bash
rake db:migrate SCOPE=blorgh VERSION=0 rake db:migrate SCOPE=blorgh VERSION=0
``` ```
@ -461,7 +461,7 @@ A typical application might have a +User+ class that would be used to represent
To keep it simple in this case, the application will have a class called +User+ which will represent the users of the application. It can be generated using this command inside the application: To keep it simple in this case, the application will have a class called +User+ which will represent the users of the application. It can be generated using this command inside the application:
```shell ```bash
rails g model user name:string rails g model user name:string
``` ```
@ -498,7 +498,7 @@ By defining that the +author+ association's object is represented by the +User+
To generate this new column, run this command within the engine: To generate this new column, run this command within the engine:
```shell ```bash
$ rails g migration add_author_id_to_blorgh_posts author_id:integer $ rails g migration add_author_id_to_blorgh_posts author_id:integer
``` ```
@ -506,7 +506,7 @@ NOTE: Due to the migration's name and the column specification after it, Rails w
This migration will need to be run on the application. To do that, it must first be copied using this command: This migration will need to be run on the application. To do that, it must first be copied using this command:
```shell ```bash
$ rake blorgh:install:migrations $ rake blorgh:install:migrations
``` ```
@ -520,7 +520,7 @@ Copied migration [timestamp]_add_author_id_to_blorgh_posts.rb from blorgh
Run this migration using this command: Run this migration using this command:
```shell ```bash
$ rake db:migrate $ rake db:migrate
``` ```

View File

@ -22,7 +22,7 @@ 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 +rails generate+:
```shell ```bash
$ rails new myapp $ rails new myapp
$ cd myapp $ cd myapp
$ rails generate $ rails generate
@ -30,7 +30,7 @@ $ rails generate
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: 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:
```shell ```bash
$ rails generate helper --help $ rails generate helper --help
``` ```
@ -55,13 +55,13 @@ Our new generator is quite simple: it inherits from +Rails::Generators::Base+ an
To invoke our new generator, we just need to do: To invoke our new generator, we just need to do:
```shell ```bash
$ rails generate initializer $ rails generate initializer
``` ```
Before we go on, let's see our brand new generator description: Before we go on, let's see our brand new generator description:
```shell ```bash
$ rails generate initializer --help $ rails generate initializer --help
``` ```
@ -83,7 +83,7 @@ Creating Generators with Generators
Generators themselves have a generator: Generators themselves have a generator:
```shell ```bash
$ rails generate generator initializer $ rails generate generator initializer
create lib/generators/initializer create lib/generators/initializer
create lib/generators/initializer/initializer_generator.rb create lib/generators/initializer/initializer_generator.rb
@ -103,7 +103,7 @@ 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): We can see that by invoking the description of this new generator (don't forget to delete the old generator file):
```shell ```bash
$ rails generate initializer --help $ rails generate initializer --help
Usage: Usage:
rails generate initializer NAME [options] rails generate initializer NAME [options]
@ -131,7 +131,7 @@ end
And let's execute our generator: And let's execute our generator:
```shell ```bash
$ rails generate initializer core_extensions $ rails generate initializer core_extensions
``` ```
@ -144,7 +144,7 @@ Generators Lookup
When you run +rails generate initializer core_extensions+ Rails requires these files in turn until one is found: When you run +rails generate initializer core_extensions+ Rails requires these files in turn until one is found:
```shell ```bash
rails/generators/initializer/initializer_generator.rb rails/generators/initializer/initializer_generator.rb
generators/initializer/initializer_generator.rb generators/initializer/initializer_generator.rb
rails/generators/initializer_generator.rb rails/generators/initializer_generator.rb
@ -170,7 +170,7 @@ end
Before we customize our workflow, let's first see what our scaffold looks like: Before we customize our workflow, let's first see what our scaffold looks like:
```shell ```bash
$ rails generate scaffold User name:string $ rails generate scaffold User name:string
invoke active_record invoke active_record
create db/migrate/20091120125558_create_users.rb create db/migrate/20091120125558_create_users.rb
@ -215,7 +215,7 @@ If we generate another resource with the scaffold generator, we can see that nei
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: 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:
```shell ```bash
$ rails generate generator rails/my_helper $ rails generate generator rails/my_helper
``` ```
@ -235,7 +235,7 @@ end
We can try out our new generator by creating a helper for users: We can try out our new generator by creating a helper for users:
```shell ```bash
$ rails generate my_helper products $ rails generate my_helper products
``` ```
@ -261,7 +261,7 @@ end
and see it in action when invoking the generator: and see it in action when invoking the generator:
```shell ```bash
$ rails generate scaffold Post body:text $ rails generate scaffold Post body:text
[...] [...]
invoke my_helper invoke my_helper
@ -344,7 +344,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: 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:
```shell ```bash
$ rails generate scaffold Comment body:text $ rails generate scaffold Comment body:text
invoke active_record invoke active_record
create db/migrate/20091120151323_create_comments.rb create db/migrate/20091120151323_create_comments.rb
@ -395,7 +395,7 @@ In the above template we specify that the application relies on the +rspec-rails
Imagine that this template was in a file called +template.rb+. We can use it to modify the outcome of the +rails new+ command by using the +-m+ option and passing in the filename: Imagine that this template was in a file called +template.rb+. We can use it to modify the outcome of the +rails new+ command by using the +-m+ option and passing in the filename:
```shell ```bash
$ rails new thud -m template.rb $ rails new thud -m template.rb
``` ```
@ -403,7 +403,7 @@ This command will generate the +Thud+ application, and then apply the template t
Templates don't have to be stored on the local system, the +-m+ option also supports online templates: Templates don't have to be stored on the local system, the +-m+ option also supports online templates:
```shell ```bash
$ rails new thud -m https://gist.github.com/722911.txt $ rails new thud -m https://gist.github.com/722911.txt
``` ```

View File

@ -79,7 +79,7 @@ TIP: The examples below use # and $ to denote superuser and regular user termina
To install Rails, use the +gem install+ command provided by RubyGems: To install Rails, use the +gem install+ command provided by RubyGems:
```shell ```bash
# gem install rails # gem install rails
``` ```
@ -90,7 +90,7 @@ Installer":http://railsinstaller.org, while Mac OS X users can use
To verify that you have everything installed correctly, you should be able to run the following: To verify that you have everything installed correctly, you should be able to run the following:
```shell ```bash
$ rails --version $ rails --version
``` ```
@ -102,7 +102,7 @@ Rails comes with a number of generators that are designed to make your developme
To use this generator, open a terminal, navigate to a directory where you have rights to create files, and type: To use this generator, open a terminal, navigate to a directory where you have rights to create files, and type:
```shell ```bash
$ rails new blog $ rails new blog
``` ```
@ -113,7 +113,7 @@ application builder accepts by running +rails new -h+.
After you create the blog application, switch to its folder to continue work directly in that application: After you create the blog application, switch to its folder to continue work directly in that application:
```shell ```bash
$ cd blog $ cd blog
``` ```
@ -148,7 +148,7 @@ To begin with, let's get some text up on screen quickly. To do this, you need to
You actually have a functional Rails application already. To see it, you need to start a web server on your development machine. You can do this by running: You actually have a functional Rails application already. To see it, you need to start a web server on your development machine. You can do this by running:
```shell ```bash
$ rails server $ rails server
``` ```
@ -172,13 +172,13 @@ A view's purpose is to display this information in a human readable format. An i
To create a new controller, you will need to run the "controller" generator and tell it you want a controller called "welcome" with an action called "index", just like this: To create a new controller, you will need to run the "controller" generator and tell it you want a controller called "welcome" with an action called "index", just like this:
```shell ```bash
$ rails generate controller welcome index $ rails generate controller welcome index
``` ```
Rails will create several files and a route for you. Rails will create several files and a route for you.
```shell ```bash
create app/controllers/welcome_controller.rb create app/controllers/welcome_controller.rb
route get "welcome/index" route get "welcome/index"
invoke erb invoke erb
@ -276,7 +276,7 @@ With the route defined, requests can now be made to +/posts/new+ in the applicat
This error is happening because this route need a controller to be defined. The route is attempting to find that controller so it can serve the request, but with the controller undefined, it just can't do that. The solution to this particular problem is simple: you need to create a controller called +PostsController+. You can do this by running this command: This error is happening because this route need a controller to be defined. The route is attempting to find that controller so it can serve the request, but with the controller undefined, it just can't do that. The solution to this particular problem is simple: you need to create a controller called +PostsController+. You can do this by running this command:
```shell ```bash
$ rails g controller posts $ rails g controller posts
``` ```
@ -432,7 +432,7 @@ a plural name. Rails provides a generator for creating models, which
most Rails developers tend to use when creating new models. most Rails developers tend to use when creating new models.
To create the new model, run this command in your terminal: To create the new model, run this command in your terminal:
```shell ```bash
$ rails generate model Post title:string text:text $ rails generate model Post title:string text:text
``` ```
@ -489,14 +489,14 @@ Migrations":migrations.html guide.
At this point, you can use a rake command to run the migration: At this point, you can use a rake command to run the migration:
```shell ```bash
$ rake db:migrate $ rake db:migrate
``` ```
Rails will execute this migration command and tell you it created the Posts Rails will execute this migration command and tell you it created the Posts
table. table.
```shell ```bash
== CreatePosts: migrating ==================================================== == CreatePosts: migrating ====================================================
-- create_table(:posts) -- create_table(:posts)
-> 0.0019s -> 0.0019s
@ -1067,7 +1067,7 @@ defined the route for the index action.
However, we don't have a +post_path+ yet, which is the reason why we However, we don't have a +post_path+ yet, which is the reason why we
received an error before. received an error before.
```shell ```bash
# rake routes # rake routes
posts GET /posts(.:format) posts#index posts GET /posts(.:format) posts#index
@ -1205,7 +1205,7 @@ end
If you run +rake routes+, you'll see that all the routes that we If you run +rake routes+, you'll see that all the routes that we
declared before are still available: declared before are still available:
```shell ```bash
# rake routes # rake routes
posts GET /posts(.:format) posts#index posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create POST /posts(.:format) posts#create
@ -1237,7 +1237,7 @@ We're going to see the same generator that we used before when creating
the +Post+ model. This time we'll create a +Comment+ model to hold the +Post+ model. This time we'll create a +Comment+ model to hold
reference of post comments. Run this command in your terminal: reference of post comments. Run this command in your terminal:
```shell ```bash
$ rails generate model Comment commenter:string body:text post:references $ rails generate model Comment commenter:string body:text post:references
``` ```
@ -1285,14 +1285,14 @@ The +t.references+ line sets up a foreign key column for the association between
the two models. And the +add_index+ line sets up an index for this association the two models. And the +add_index+ line sets up an index for this association
column. Go ahead and run the migration: column. Go ahead and run the migration:
```shell ```bash
$ rake db:migrate $ rake db:migrate
``` ```
Rails is smart enough to only execute the migrations that have not already been Rails is smart enough to only execute the migrations that have not already been
run against the current database, so in this case you will just see: run against the current database, so in this case you will just see:
```shell ```bash
== CreateComments: migrating ================================================= == CreateComments: migrating =================================================
-- create_table(:comments) -- create_table(:comments)
-> 0.0008s -> 0.0008s
@ -1362,7 +1362,7 @@ In":routing.html guide.
With the model in hand, you can turn your attention to creating a matching 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: controller. Again, we'll use the same generator we used before:
```shell ```bash
$ rails generate controller Comments $ rails generate controller Comments
``` ```

View File

@ -109,7 +109,7 @@ render :nothing => true
If you look at the response for this using cURL, you will see the following: If you look at the response for this using cURL, you will see the following:
```shell ```bash
$ curl -i 127.0.0.1:3000/books $ curl -i 127.0.0.1:3000/books
HTTP/1.1 200 OK HTTP/1.1 200 OK
Connection: close Connection: close
@ -601,7 +601,7 @@ head :bad_request
This would produce the following header: This would produce the following header:
```shell ```bash
HTTP/1.1 400 Bad Request HTTP/1.1 400 Bad Request
Connection: close Connection: close
Date: Sun, 24 Jan 2010 12:15:53 GMT Date: Sun, 24 Jan 2010 12:15:53 GMT
@ -620,7 +620,7 @@ head :created, :location => photo_path(@photo)
Which would produce: Which would produce:
```shell ```bash
HTTP/1.1 201 Created HTTP/1.1 201 Created
Connection: close Connection: close
Date: Sun, 24 Jan 2010 12:16:44 GMT Date: Sun, 24 Jan 2010 12:16:44 GMT

View File

@ -231,7 +231,7 @@ a new model. This migration will already contain instructions for creating the
relevant table. If you tell Rails what columns you want, then statements for relevant table. If you tell Rails what columns you want, then statements for
adding these columns will also be created. For example, running adding these columns will also be created. For example, running
```shell ```bash
$ rails generate model Product name:string description:text $ rails generate model Product name:string description:text
``` ```
@ -260,7 +260,7 @@ by Active Record).
If you are creating migrations for other purposes (e.g., to add a column If you are creating migrations for other purposes (e.g., to add a column
to an existing table) then you can also use the migration generator: to an existing table) then you can also use the migration generator:
```shell ```bash
$ rails generate migration AddPartNumberToProducts $ rails generate migration AddPartNumberToProducts
``` ```
@ -277,7 +277,7 @@ If the migration name is of the form "AddXXXToYYY" or "RemoveXXXFromYYY" and is
followed by a list of column names and types then a migration containing the followed by a list of column names and types then a migration containing the
appropriate +add_column+ and +remove_column+ statements will be created. appropriate +add_column+ and +remove_column+ statements will be created.
```shell ```bash
$ rails generate migration AddPartNumberToProducts part_number:string $ rails generate migration AddPartNumberToProducts part_number:string
``` ```
@ -293,7 +293,7 @@ end
Similarly, Similarly,
```shell ```bash
$ rails generate migration RemovePartNumberFromProducts part_number:string $ rails generate migration RemovePartNumberFromProducts part_number:string
``` ```
@ -313,7 +313,7 @@ end
You are not limited to one magically generated column. For example You are not limited to one magically generated column. For example
```shell ```bash
$ rails generate migration AddDetailsToProducts part_number:string price:decimal $ rails generate migration AddDetailsToProducts part_number:string price:decimal
``` ```
@ -338,7 +338,7 @@ the original data types defined when you made the original changes.
Also, the generator accepts column type as +references+(also available as +belongs_to+). For instance Also, the generator accepts column type as +references+(also available as +belongs_to+). For instance
```shell ```bash
$ rails generate migration AddUserRefToProducts user:references $ rails generate migration AddUserRefToProducts user:references
``` ```
@ -366,7 +366,7 @@ following modifiers:
For instance, running For instance, running
```shell ```bash
$ rails generate migration AddDetailsToProducts price:decimal{5,2} supplier:references{polymorphic} $ rails generate migration AddDetailsToProducts price:decimal{5,2} supplier:references{polymorphic}
``` ```
@ -636,7 +636,7 @@ If you specify a target version, Active Record will run the required migrations
is the numerical prefix on the migration's filename. For example, to migrate is the numerical prefix on the migration's filename. For example, to migrate
to version 20080906120000 run to version 20080906120000 run
```shell ```bash
$ rake db:migrate VERSION=20080906120000 $ rake db:migrate VERSION=20080906120000
``` ```
@ -652,14 +652,14 @@ A common task is to rollback the last migration. For example, if you made a
mistake in it and wish to correct it. Rather than tracking down the version mistake in it and wish to correct it. Rather than tracking down the version
number associated with the previous migration you can run number associated with the previous migration you can run
```shell ```bash
$ rake db:rollback $ rake db:rollback
``` ```
This will run the +down+ method from the latest migration. If you need to undo This will run the +down+ method from the latest migration. If you need to undo
several migrations you can provide a +STEP+ parameter: several migrations you can provide a +STEP+ parameter:
```shell ```bash
$ rake db:rollback STEP=3 $ rake db:rollback STEP=3
``` ```
@ -669,7 +669,7 @@ The +db:migrate:redo+ task is a shortcut for doing a rollback and then migrating
back up again. As with the +db:rollback+ task, you can use the +STEP+ parameter back up again. As with the +db:rollback+ task, you can use the +STEP+ parameter
if you need to go more than one version back, for example if you need to go more than one version back, for example
```shell ```bash
$ rake db:migrate:redo STEP=3 $ rake db:migrate:redo STEP=3
``` ```
@ -692,7 +692,7 @@ If you need to run a specific migration up or down, the +db:migrate:up+ and
the corresponding migration will have its +up+ or +down+ method invoked, for the corresponding migration will have its +up+ or +down+ method invoked, for
example, example,
```shell ```bash
$ rake db:migrate:up VERSION=20080906120000 $ rake db:migrate:up VERSION=20080906120000
``` ```
@ -705,7 +705,7 @@ that it has already been run.
By default migrations tell you exactly what they're doing and how long it took. By default migrations tell you exactly what they're doing and how long it took.
A migration creating a table and adding an index might produce output like this A migration creating a table and adding an index might produce output like this
```shell ```bash
== CreateProducts: migrating ================================================= == CreateProducts: migrating =================================================
-- create_table(:products) -- create_table(:products)
-> 0.0028s -> 0.0028s
@ -749,7 +749,7 @@ end
generates the following output generates the following output
```shell ```bash
== CreateProducts: migrating ================================================= == CreateProducts: migrating =================================================
-- Created a table -- Created a table
-> and an index! -> and an index!

View File

@ -53,7 +53,7 @@ the application's homepage.
Rails provides a generator called +performance_test+ for creating new Rails provides a generator called +performance_test+ for creating new
performance tests: performance tests:
```shell ```bash
$ rails generate performance_test homepage $ rails generate performance_test homepage
``` ```
@ -181,7 +181,7 @@ By default, each test case is run *4 times* in benchmarking mode.
To run performance tests in benchmarking mode: To run performance tests in benchmarking mode:
```shell ```bash
$ rake test:benchmark $ rake test:benchmark
``` ```
@ -194,7 +194,7 @@ test case is run *once* in profiling mode.
To run performance tests in profiling mode: To run performance tests in profiling mode:
```shell ```bash
$ rake test:profile $ rake test:profile
``` ```
@ -278,7 +278,7 @@ In benchmarking mode, performance tests generate two types of outputs.
This is the primary form of output in benchmarking mode. Example: This is the primary form of output in benchmarking mode. Example:
```shell ```bash
BrowsingTest#test_homepage (31 ms warmup) BrowsingTest#test_homepage (31 ms warmup)
wall_time: 6 ms wall_time: 6 ms
memory: 437.27 KB memory: 437.27 KB
@ -305,7 +305,7 @@ be very helpful in analyzing the effects of code changes.
Sample output of +BrowsingTest#test_homepage_wall_time.csv+: Sample output of +BrowsingTest#test_homepage_wall_time.csv+:
```shell ```bash
measurement,created_at,app,rails,ruby,platform measurement,created_at,app,rails,ruby,platform
0.00738224999999992,2009-01-08T03:40:29Z,,3.0.0,ruby-1.8.7.249,x86_64-linux 0.00738224999999992,2009-01-08T03:40:29Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
0.00755874999999984,2009-01-08T03:46:18Z,,3.0.0,ruby-1.8.7.249,x86_64-linux 0.00755874999999984,2009-01-08T03:46:18Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
@ -330,7 +330,7 @@ their availability across interpreters is given below.
This is a very basic form of output in profiling mode: This is a very basic form of output in profiling mode:
```shell ```bash
BrowsingTest#test_homepage (58 ms warmup) BrowsingTest#test_homepage (58 ms warmup)
process_time: 63 ms process_time: 63 ms
memory: 832.13 KB memory: 832.13 KB
@ -405,7 +405,7 @@ symbol array with each name "underscored.":http://api.rubyonrails.org/classes/St
Performance tests are run in the +test+ environment. But running performance Performance tests are run in the +test+ environment. But running performance
tests will set the following configuration parameters: tests will set the following configuration parameters:
```shell ```bash
ActionController::Base.perform_caching = true ActionController::Base.perform_caching = true
ActiveSupport::Dependencies.mechanism = :require ActiveSupport::Dependencies.mechanism = :require
Rails.logger.level = ActiveSupport::BufferedLogger::INFO Rails.logger.level = ActiveSupport::BufferedLogger::INFO
@ -439,7 +439,7 @@ The process of installing a patched Ruby interpreter is very easy if you let RVM
do the hard work. All of the following RVM commands will provide you with a do the hard work. All of the following RVM commands will provide you with a
patched Ruby interpreter: patched Ruby interpreter:
```shell ```bash
$ rvm install 1.9.2-p180 --patch gcdata $ rvm install 1.9.2-p180 --patch gcdata
$ rvm install 1.8.7 --patch ruby187gc $ rvm install 1.8.7 --patch ruby187gc
$ rvm install 1.9.2-p180 --patch ~/Downloads/downloaded_gcdata_patch.patch $ rvm install 1.9.2-p180 --patch ~/Downloads/downloaded_gcdata_patch.patch
@ -448,7 +448,7 @@ $ rvm install 1.9.2-p180 --patch ~/Downloads/downloaded_gcdata_patch.patch
You can even keep your regular interpreter by assigning a name to the patched You can even keep your regular interpreter by assigning a name to the patched
one: one:
```shell ```bash
$ rvm install 1.9.2-p180 --patch gcdata --name gcdata $ rvm install 1.9.2-p180 --patch gcdata --name gcdata
$ rvm use 1.9.2-p180 # your regular ruby $ rvm use 1.9.2-p180 # your regular ruby
$ rvm use 1.9.2-p180-gcdata # your patched ruby $ rvm use 1.9.2-p180-gcdata # your patched ruby
@ -464,7 +464,7 @@ Ruby binary inside your home directory.
##### Download and Extract ##### Download and Extract
```shell ```bash
$ mkdir rubygc $ mkdir rubygc
$ wget <the version you want from ftp://ftp.ruby-lang.org/pub/ruby> $ wget <the version you want from ftp://ftp.ruby-lang.org/pub/ruby>
$ tar -xzvf <ruby-version.tar.gz> $ tar -xzvf <ruby-version.tar.gz>
@ -473,7 +473,7 @@ $ cd <ruby-version>
##### Apply the Patch ##### Apply the Patch
```shell ```bash
$ curl http://github.com/wayneeseguin/rvm/raw/master/patches/ruby/1.9.2/p180/gcdata.patch | patch -p0 # if you're on 1.9.2! $ curl http://github.com/wayneeseguin/rvm/raw/master/patches/ruby/1.9.2/p180/gcdata.patch | patch -p0 # if you're on 1.9.2!
$ curl http://github.com/wayneeseguin/rvm/raw/master/patches/ruby/1.8.7/ruby187gc.patch | patch -p0 # if you're on 1.8.7! $ curl http://github.com/wayneeseguin/rvm/raw/master/patches/ruby/1.8.7/ruby187gc.patch | patch -p0 # if you're on 1.8.7!
``` ```
@ -484,7 +484,7 @@ The following will install Ruby in your home directory's +/rubygc+ directory.
Make sure to replace +&lt;homedir&gt;+ with a full patch to your actual home Make sure to replace +&lt;homedir&gt;+ with a full patch to your actual home
directory. directory.
```shell ```bash
$ ./configure --prefix=/<homedir>/rubygc $ ./configure --prefix=/<homedir>/rubygc
$ make && make install $ make && make install
``` ```
@ -493,7 +493,7 @@ $ make && make install
For convenience, add the following lines in your +~/.profile+: For convenience, add the following lines in your +~/.profile+:
```shell ```bash
alias gcruby='~/rubygc/bin/ruby' alias gcruby='~/rubygc/bin/ruby'
alias gcrake='~/rubygc/bin/rake' alias gcrake='~/rubygc/bin/rake'
alias gcgem='~/rubygc/bin/gem' alias gcgem='~/rubygc/bin/gem'
@ -525,7 +525,7 @@ performance testing:
Usage: Usage:
```shell ```bash
Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS] Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS]
-r, --runs N Number of runs. -r, --runs N Number of runs.
Default: 4 Default: 4
@ -537,7 +537,7 @@ Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS]
Example: Example:
```shell ```bash
$ rails benchmarker 'Item.all' 'CouchItem.all' --runs 3 --metrics wall_time,memory $ rails benchmarker 'Item.all' 'CouchItem.all' --runs 3 --metrics wall_time,memory
``` ```
@ -545,7 +545,7 @@ $ rails benchmarker 'Item.all' 'CouchItem.all' --runs 3 --metrics wall_time,memo
Usage: Usage:
```shell ```bash
Usage: rails profiler 'Ruby.code' 'Ruby.more_code' ... [OPTS] Usage: rails profiler 'Ruby.code' 'Ruby.more_code' ... [OPTS]
-r, --runs N Number of runs. -r, --runs N Number of runs.
Default: 1 Default: 1
@ -559,7 +559,7 @@ Usage: rails profiler 'Ruby.code' 'Ruby.more_code' ... [OPTS]
Example: Example:
```shell ```bash
$ rails profiler 'Item.all' 'CouchItem.all' --runs 2 --metrics process_time --formats flat $ rails profiler 'Item.all' 'CouchItem.all' --runs 2 --metrics process_time --formats flat
``` ```
@ -624,7 +624,7 @@ Request Logging
Rails log files contain very useful information about the time taken to serve Rails log files contain very useful information about the time taken to serve
each request. Here's a typical log file entry: each request. Here's a typical log file entry:
```shell ```bash
Processing ItemsController#index (for 127.0.0.1 at 2009-01-08 03:06:39) [GET] Processing ItemsController#index (for 127.0.0.1 at 2009-01-08 03:06:39) [GET]
Rendering template within layouts/items Rendering template within layouts/items
Rendering items/index Rendering items/index
@ -633,7 +633,7 @@ Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items]
For this section, we're only interested in the last line: For this section, we're only interested in the last line:
```shell ```bash
Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items] Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items]
``` ```

View File

@ -41,7 +41,7 @@ Rails 3.1 ships with a +rails plugin new+ command which creates a
to run integration tests using a dummy Rails application. See usage to run integration tests using a dummy Rails application. See usage
and options by asking for help: and options by asking for help:
```shell ```bash
$ rails plugin --help $ rails plugin --help
``` ```
@ -53,7 +53,7 @@ You can navigate to the directory that contains the plugin, run the +bundle inst
You should see: You should see:
```shell ```bash
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips 2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
``` ```
@ -80,7 +80,7 @@ end
Run +rake+ to run the test. This test should fail because we haven't implemented the +to_squawk+ method: Run +rake+ to run the test. This test should fail because we haven't implemented the +to_squawk+ method:
```shell ```bash
1) Error: 1) Error:
test_to_squawk_prepends_the_word_squawk(CoreExtTest): test_to_squawk_prepends_the_word_squawk(CoreExtTest):
NoMethodError: undefined method `to_squawk' for "Hello World":String NoMethodError: undefined method `to_squawk' for "Hello World":String
@ -114,13 +114,13 @@ end
To test that your method does what it says it does, run the unit tests with +rake+ from your plugin directory. To test that your method does what it says it does, run the unit tests with +rake+ from your plugin directory.
```shell ```bash
3 tests, 3 assertions, 0 failures, 0 errors, 0 skips 3 tests, 3 assertions, 0 failures, 0 errors, 0 skips
``` ```
To see this in action, change to the test/dummy directory, fire up a console and start squawking: To see this in action, change to the test/dummy directory, fire up a console and start squawking:
```shell ```bash
$ rails console $ rails console
>> "Hello World".to_squawk >> "Hello World".to_squawk
=> "squawk! Hello World" => "squawk! Hello World"
@ -191,7 +191,7 @@ end
When you run +rake+, you should see the following: When you run +rake+, you should see the following:
```shell ```bash
1) Error: 1) Error:
test_a_hickwalls_yaffle_text_field_should_be_last_squawk(ActsAsYaffleTest): test_a_hickwalls_yaffle_text_field_should_be_last_squawk(ActsAsYaffleTest):
NameError: uninitialized constant ActsAsYaffleTest::Hickwall NameError: uninitialized constant ActsAsYaffleTest::Hickwall
@ -209,7 +209,7 @@ This tells us that we don't have the necessary models (Hickwall and Wickwall) th
We can easily generate these models in our "dummy" Rails application by running the following commands from the We can easily generate these models in our "dummy" Rails application by running the following commands from the
test/dummy directory: test/dummy directory:
```shell ```bash
$ cd test/dummy $ cd test/dummy
$ rails generate model Hickwall last_squawk:string $ rails generate model Hickwall last_squawk:string
$ rails generate model Wickwall last_squawk:string last_tweet:string $ rails generate model Wickwall last_squawk:string last_tweet:string
@ -218,7 +218,7 @@ $ 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 Now you can create the necessary database tables in your testing database by navigating to your dummy app
and migrating the database. First and migrating the database. First
```shell ```bash
$ cd test/dummy $ cd test/dummy
$ rake db:migrate $ rake db:migrate
$ rake db:test:prepare $ rake db:test:prepare
@ -266,7 +266,7 @@ ActiveRecord::Base.send :include, Yaffle::ActsAsYaffle
You can then return to the root directory (+cd ../..+) of your plugin and rerun the tests using +rake+. You can then return to the root directory (+cd ../..+) of your plugin and rerun the tests using +rake+.
```shell ```bash
1) Error: 1) Error:
test_a_hickwalls_yaffle_text_field_should_be_last_squawk(ActsAsYaffleTest): test_a_hickwalls_yaffle_text_field_should_be_last_squawk(ActsAsYaffleTest):
NoMethodError: undefined method `yaffle_text_field' for #<Class:0x000001016661b8> NoMethodError: undefined method `yaffle_text_field' for #<Class:0x000001016661b8>
@ -309,7 +309,7 @@ ActiveRecord::Base.send :include, Yaffle::ActsAsYaffle
When you run +rake+ you should see the tests all pass: When you run +rake+ you should see the tests all pass:
```shell ```bash
5 tests, 5 assertions, 0 failures, 0 errors, 0 skips 5 tests, 5 assertions, 0 failures, 0 errors, 0 skips
``` ```
@ -383,7 +383,7 @@ ActiveRecord::Base.send :include, Yaffle::ActsAsYaffle
Run +rake+ one final time and you should see: Run +rake+ one final time and you should see:
```shell ```bash
7 tests, 7 assertions, 0 failures, 0 errors, 0 skips 7 tests, 7 assertions, 0 failures, 0 errors, 0 skips
``` ```
@ -426,7 +426,7 @@ Once your README is solid, go through and add rdoc comments to all of the method
Once your comments are good to go, navigate to your plugin directory and run: Once your comments are good to go, navigate to your plugin directory and run:
```shell ```bash
$ rake rdoc $ rake rdoc
``` ```

View File

@ -15,14 +15,14 @@ Usage
To apply a template, you need to provide the Rails generator with the location of the template you wish to apply, using -m option. This can either be path to a file or a URL. To apply a template, you need to provide the Rails generator with the location of the template you wish to apply, using -m option. This can either be path to a file or a URL.
```shell ```bash
$ rails new blog -m ~/template.rb $ rails new blog -m ~/template.rb
$ rails new blog -m http://example.com/template.rb $ rails new blog -m http://example.com/template.rb
``` ```
You can use the rake task +rails:template+ to apply templates to an existing Rails application. The location of the template needs to be passed in to an environment variable named LOCATION. Again, this can either be path to a file or a URL. You can use the rake task +rails:template+ to apply templates to an existing Rails application. The location of the template needs to be passed in to an environment variable named LOCATION. Again, this can either be path to a file or a URL.
```shell ```bash
$ rake rails:template LOCATION=~/template.rb $ rake rails:template LOCATION=~/template.rb
$ rake rails:template LOCATION=http://example.com/template.rb $ rake rails:template LOCATION=http://example.com/template.rb
``` ```

View File

@ -85,13 +85,13 @@ run ApplicationName::Application
And start the server: And start the server:
```shell ```bash
$ rackup config.ru $ rackup config.ru
``` ```
To find out more about different +rackup+ options: To find out more about different +rackup+ options:
```shell ```bash
$ rackup --help $ rackup --help
``` ```
@ -106,7 +106,7 @@ NOTE: +ActionDispatch::MiddlewareStack+ is Rails' equivalent of +Rack::Builder+,
Rails has a handy rake task for inspecting the middleware stack in use: Rails has a handy rake task for inspecting the middleware stack in use:
```shell ```bash
$ rake middleware $ rake middleware
``` ```
@ -189,7 +189,7 @@ config.middleware.delete "Rack::Lock"
And now if you inspect the middleware stack, you'll find that +Rack::Lock+ will not be part of it. And now if you inspect the middleware stack, you'll find that +Rack::Lock+ will not be part of it.
```shell ```bash
$ rake middleware $ rake middleware
(in /Users/lifo/Rails/blog) (in /Users/lifo/Rails/blog)
use ActionDispatch::Static use ActionDispatch::Static

View File

@ -913,7 +913,7 @@ edit_user GET /users/:id/edit(.:format) users#edit
You may restrict the listing to the routes that map to a particular controller setting the +CONTROLLER+ environment variable: You may restrict the listing to the routes that map to a particular controller setting the +CONTROLLER+ environment variable:
```shell ```bash
$ CONTROLLER=users rake routes $ CONTROLLER=users rake routes
``` ```

View File

@ -34,7 +34,7 @@ A dedicated test database allows you to set up and interact with test data in is
Rails creates a +test+ folder for you as soon as you create a Rails project using +rails new+ _application_name_. If you list the contents of this folder then you shall see: Rails creates a +test+ folder for you as soon as you create a Rails project using +rails new+ _application_name_. If you list the contents of this folder then you shall see:
```shell ```bash
$ ls -F test $ ls -F test
fixtures/ functional/ integration/ performance/ test_helper.rb unit/ fixtures/ functional/ integration/ performance/ test_helper.rb unit/
@ -123,7 +123,7 @@ NOTE: For more information on Rails <i>scaffolding</i>, refer to "Getting Starte
When you use +rails generate scaffold+, for a resource among other things it creates a test stub in the +test/unit+ folder: When you use +rails generate scaffold+, for a resource among other things it creates a test stub in the +test/unit+ folder:
```shell ```bash
$ rails generate scaffold post title:string body:text $ rails generate scaffold post title:string body:text
... ...
create app/models/post.rb create app/models/post.rb
@ -198,7 +198,7 @@ Every test contains one or more assertions. Only when all the assertions are suc
Before you can run your tests, you need to ensure that the test database structure is current. For this you can use the following rake commands: Before you can run your tests, you need to ensure that the test database structure is current. For this you can use the following rake commands:
```shell ```bash
$ rake db:migrate $ rake db:migrate
... ...
$ rake db:test:load $ rake db:test:load
@ -223,7 +223,7 @@ TIP: You can see all these rake tasks and their descriptions by running +rake --
Running a test is as simple as invoking the file containing the test cases through Ruby: Running a test is as simple as invoking the file containing the test cases through Ruby:
```shell ```bash
$ ruby -Itest test/unit/post_test.rb $ ruby -Itest test/unit/post_test.rb
Loaded suite unit/post_test Loaded suite unit/post_test
@ -238,7 +238,7 @@ This will run all the test methods from the test case. Note that +test_helper.rb
You can also run a particular test method from the test case by using the +-n+ switch with the +test method name+. You can also run a particular test method from the test case by using the +-n+ switch with the +test method name+.
```shell ```bash
$ ruby -Itest test/unit/post_test.rb -n test_the_truth $ ruby -Itest test/unit/post_test.rb -n test_the_truth
Loaded suite unit/post_test Loaded suite unit/post_test
@ -262,7 +262,7 @@ end
Let us run this newly added test. Let us run this newly added test.
```shell ```bash
$ ruby unit/post_test.rb -n test_should_not_save_post_without_title $ ruby unit/post_test.rb -n test_should_not_save_post_without_title
Loaded suite -e Loaded suite -e
Started Started
@ -287,7 +287,7 @@ end
Running this test shows the friendlier assertion message: Running this test shows the friendlier assertion message:
```shell ```bash
1) Failure: 1) Failure:
test_should_not_save_post_without_title(PostTest) [/test/unit/post_test.rb:6]: test_should_not_save_post_without_title(PostTest) [/test/unit/post_test.rb:6]:
Saved the post without a title. Saved the post without a title.
@ -304,7 +304,7 @@ end
Now the test should pass. Let us verify by running the test again: Now the test should pass. Let us verify by running the test again:
```shell ```bash
$ ruby unit/post_test.rb -n test_should_not_save_post_without_title $ ruby unit/post_test.rb -n test_should_not_save_post_without_title
Loaded suite unit/post_test Loaded suite unit/post_test
Started Started
@ -330,7 +330,7 @@ end
Now you can see even more output in the console from running the tests: Now you can see even more output in the console from running the tests:
```shell ```bash
$ ruby unit/post_test.rb -n test_should_report_error $ ruby unit/post_test.rb -n test_should_report_error
Loaded suite -e Loaded suite -e
Started Started
@ -627,7 +627,7 @@ Integration tests are used to test the interaction among any number of controlle
Unlike Unit and Functional tests, integration tests have to be explicitly created under the 'test/integration' folder within your application. Rails provides a generator to create an integration test skeleton for you. Unlike Unit and Functional tests, integration tests have to be explicitly created under the 'test/integration' folder within your application. Rails provides a generator to create an integration test skeleton for you.
```shell ```bash
$ rails generate integration_test user_flows $ rails generate integration_test user_flows
exists test/integration/ exists test/integration/
create test/integration/user_flows_test.rb create test/integration/user_flows_test.rb