diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md index 32706adb21e..21fb11c89c4 100644 --- a/guides/source/action_controller_overview.md +++ b/guides/source/action_controller_overview.md @@ -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: -```shell +```bash GET /clients/1.pdf ``` diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md index d952d28c8e7..38fd49a161c 100644 --- a/guides/source/action_mailer_basics.md +++ b/guides/source/action_mailer_basics.md @@ -21,7 +21,7 @@ This section will provide a step-by-step guide to creating a mailer and its view #### Create the Mailer -```shell +```bash $ rails generate mailer UserMailer create app/mailers/user_mailer.rb invoke erb @@ -111,7 +111,7 @@ Setting this up is painfully simple. First off, we need to create a simple `User` scaffold: -```shell +```bash $ rails generate scaffold user name:string email:string login:string $ rake db:migrate ``` diff --git a/guides/source/action_view_overview.md b/guides/source/action_view_overview.md index 08ffb2d3897..a4fd80d59c4 100644 --- a/guides/source/action_view_overview.md +++ b/guides/source/action_view_overview.md @@ -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: -```shell +```bash $ rails generate scaffold post [...] 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: -```shell +```bash $ gem install actionpack $ 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/+ -```shell +```bash $ 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: -```shell +```bash $ gem install actionpack $ gem install sinatra ``` @@ -107,7 +107,7 @@ end Then, we can run the application: -```shell +```bash $ ruby hello_world.rb ``` diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index e54557c4dc6..bad38e38410 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -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: -```shell +```bash ActiveModel::MissingAttributeError: missing attribute: ``` diff --git a/guides/source/active_record_validations_callbacks.md b/guides/source/active_record_validations_callbacks.md index 0f5a6f169a4..551cd983e99 100644 --- a/guides/source/active_record_validations_callbacks.md +++ b/guides/source/active_record_validations_callbacks.md @@ -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. -```shell +```bash $ rails generate observer User ``` diff --git a/guides/source/ajax_on_rails.md b/guides/source/ajax_on_rails.md index da54ae2a2d3..7317d470972 100644 --- a/guides/source/ajax_on_rails.md +++ b/guides/source/ajax_on_rails.md @@ -85,7 +85,7 @@ By default, +:defaults+ loads jQuery. You can also choose to use Prototype instead of jQuery and specify the option using +-j+ switch while generating the application. -```shell +```bash rails new app_name -j prototype ``` diff --git a/guides/source/command_line.md b/guides/source/command_line.md index 875d0000b95..83ed244d491 100644 --- a/guides/source/command_line.md +++ b/guides/source/command_line.md @@ -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. -```shell +```bash $ rails new commandsapp create 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: -```shell +```bash $ cd commandsapp $ rails server => 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+. -```shell +```bash $ 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`. -```shell +```bash $ rails generate 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+. -```shell +```bash $ rails generate controller 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. -```shell +```bash $ rails generate controller Greetings hello create app/controllers/greetings_controller.rb 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+. -```shell +```bash $ rails server => 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. -```shell +```bash $ rails generate model Usage: 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. -```shell +```bash $ rails generate scaffold HighScore game:string score:integer invoke active_record 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. -```shell +```bash $ rake db:migrate == CreateHighScores: migrating =============================================== -- 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. -```shell +```bash $ 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. -```shell +```bash $ rails console staging ``` If you wish to test out some code without changing any data, you can do that by invoking +rails console --sandbox+. -```shell +```bash $ rails console --sandbox Loading development environment in sandbox (Rails 3.2.3) 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: -```shell +```bash $ 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. -```shell +```bash $ 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`. -```shell +```bash $ rails generate model Oops invoke active_record create db/migrate/20120528062523_create_oops.rb @@ -330,7 +330,7 @@ $ rails generate model Oops create test/unit/oops_test.rb create test/fixtures/oops.yml ``` -```shell +```bash $ rails destroy model Oops invoke active_record 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. -```shell +```bash $ rake --tasks rake about # List versions of all Rails frameworks and the environment 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. -```shell +```bash $ rake about About your application's environment 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. -```shell +```bash $ rake notes (in /home/foobar/commandsapp) 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. -```shell +```bash $ rake notes:fixme (in /home/foobar/commandsapp) 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+. -```shell +```bash $ rake notes:custom ANNOTATION=BUG (in /home/foobar/commandsapp) 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+. -```shell +```bash $ export SOURCE_ANNOTATION_DIRECTORIES='rspec,vendor' $ rake notes (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: -```shell +```bash rake task_name rake "task_name[value 1]" # entire argument string should be quoted 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: -```shell +```bash $ mkdir gitapp $ cd gitapp $ 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: -```shell +```bash $ cat config/database.yml # 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+: -```shell +```bash $ sudo gem install mongrel Building native extensions. This could take a while... Building native extensions. This could take a while... diff --git a/guides/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md index ec7d7e20391..34f8f475afe 100644 --- a/guides/source/contributing_to_ruby_on_rails.md +++ b/guides/source/contributing_to_ruby_on_rails.md @@ -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: -```shell +```bash $ git clone git://github.com/rails/rails.git $ 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 -```shell +```bash $ sudo apt-get install libxml2 libxml2-dev libxslt1-dev ``` If you are on Fedora or CentOS, you can run -```shell +```bash $ 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 -```shell +```bash $ sudo apt-get install sqlite3 libsqlite3-dev ``` And if you are on Fedora or CentOS, you're done with -```shell +```bash $ sudo yum install sqlite3 sqlite3-devel ``` Get a recent version of "Bundler":http://gembundler.com/: -```shell +```bash $ gem install bundler $ gem update bundler ``` and run: -```shell +```bash $ 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: -```shell +```bash $ 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: -```shell +```bash $ cd actionpack $ 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: -```shell +```bash $ cd railties $ TEST_DIR=generators bundle exec rake test ``` You can run any single test separately too: -```shell +```bash $ cd actionpack $ 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 -```shell +```bash $ sudo apt-get install mysql-server libmysqlclient15-dev $ sudo apt-get install postgresql postgresql-client postgresql-contrib libpq-dev ``` On Fedora or CentOS, just run: -```shell +```bash $ sudo yum install mysql-server mysql-devel $ sudo yum install postgresql-server postgresql-devel ``` After that run: -```shell +```bash $ rm .bundle/config $ 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: -```shell +```bash mysql> GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost'; mysql> GRANT ALL PRIVILEGES ON activerecord_unittest2.* @@ -183,20 +183,20 @@ mysql> GRANT ALL PRIVILEGES ON activerecord_unittest2.* and create the test databases: -```shell +```bash $ cd activerecord $ 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 -```shell +```bash $ sudo -u postgres createuser --superuser $USER ``` and then create the test databases with -```shell +```bash $ cd activerecord $ 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: -```shell +```bash $ cd activerecord $ bundle exec rake test_sqlite3 ``` You can now run the tests as you did for +sqlite3+. The tasks are respectively -```shell +```bash test_mysql test_mysql2 test_postgresql @@ -227,7 +227,7 @@ test_postgresql Finally, -```shell +```bash $ 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: -```shell +```bash $ 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: -```shell +```bash $ 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: -```shell +```bash $ git branch --track 3-0-stable origin/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: -```shell +```bash $ 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. -```shell +```bash $ git remote add JohnSmith git://github.com/JohnSmith/rails.git $ 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: -```shell +```bash $ git clone git://github.com/rails/rails.git ``` and create a dedicated branch: -```shell +```bash $ cd rails $ 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: -```shell +```bash $ git commit -a ``` @@ -447,14 +447,14 @@ TIP. Please squash your commits into a single commit when appropriate. This simp It’s pretty likely that other changes to master have happened while you were working. Go get them: -```shell +```bash $ git checkout master $ git pull --rebase ``` Now reapply your patch on top of the latest changes: -```shell +```bash $ git checkout my_new_branch $ 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: -```shell +```bash $ git remote add mine git@github.com:/rails.git ``` Push to your remote: -```shell +```bash $ 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: -```shell +```bash $ git remote add rails git://github.com/rails/rails.git ``` Download new commits and branches from the official repository: -```shell +```bash $ git fetch rails ``` Merge the new content: -```shell +```bash $ git checkout master $ git rebase rails/master ``` Update your fork: -```shell +```bash $ git push origin master ``` If you want to update another branches: -```shell +```bash $ git checkout branch_name $ git rebase rails/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: -```shell +```bash $ git log master..HEAD ``` Then extract the diff: -```shell +```bash $ git format-patch master --stdout > ~/my_changes.patch ``` Switch over to the target branch and apply your changes: -```shell +```bash $ git checkout -b my_backport_branch 3-2-stable $ git apply ~/my_changes.patch ``` diff --git a/guides/source/debugging_rails_applications.md b/guides/source/debugging_rails_applications.md index d4553e7b74b..35d4f5fb8fe 100644 --- a/guides/source/debugging_rails_applications.md +++ b/guides/source/debugging_rails_applications.md @@ -174,7 +174,7 @@ end 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] Session ID: BAh7BzoMY3NyZl9pZCIlMDY5MWU1M2I1ZDRjODBlMzkyMWI1OTg2NWQyNzViZjYiCmZsYXNoSUM6J0FjdGl 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: -```shell +```bash $ gem install debugger ``` @@ -235,13 +235,13 @@ end If you see the message in the console or logs: -```shell +```bash ***** Debugger requested, but was not available: Start server with --debugger to enable ***** ``` Make sure you have started your web server with the option +--debugger+: -```shell +```bash $ rails server --debugger => Booting WEBrick => 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: -```shell +```bash @posts = Post.all (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?) -```shell +```bash (rdb:7) help ruby-debug help v0.10.2 Type 'help ' 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 +=>+. -```shell +```bash (rdb:7) list [1, 10] in /PathToProject/posts_controller.rb 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. -```shell +```bash (rdb:7) l [11, 20] in /PathTo/project/app/controllers/posts_controller.rb 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-+) -```shell +```bash (rdb:7) l- [1, 10] in /PathToProject/posts_controller.rb 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+. Finally, to see where you are in the code again you can type +list=+ -```shell +```bash (rdb:7) list= [1, 10] in /PathToProject/posts_controller.rb 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. -```shell +```bash (rdb:5) where #0 PostsController.index 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. -```shell +```bash (rdb:5) frame 2 #2 ActionController::Base.perform_action_without_filters 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: -```shell +```bash @posts = Post.all (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"] @@ -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). -```shell +```bash (rdb:11) next Processing PostsController#index (for 127.0.0.1 at 2008-09-04 19:51:34) [GET] Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA==--b16e91b992453a8cc201694d660147bba8b0fd0e @@ -424,7 +424,7 @@ respond_to do |format| And then ask again for the instance_variables: -```shell +```bash (rdb:11) instance_variables.include? "@posts" 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: -```shell +```bash var (rdb:1) v[ar] const show constants of object (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: -```shell +```bash (rdb:9) var local __dbg_verbose_save => false ``` You can also inspect for an object method this way: -```shell +```bash (rdb:9) var instance Post.new @attributes = {"updated_at"=>nil, "body"=>nil, "title"=>nil, "published"=>nil, "created_at"... @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. -```shell +```bash (rdb:1) display @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. -```shell +```bash $ rails console Loading development environment (Rails 3.1.0) >> require "debugger" @@ -512,7 +512,7 @@ Loading development environment (Rails 3.1.0) With the code stopped, take a look around: -```shell +```bash (rdb:1) list [2, 9] in /PathTo/project/app/models/author.rb 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. -```shell +```bash (rdb:1) var instance @attributes = {"updated_at"=>"2008-07-31 12:46:10", "id"=>"1", "first_name"=>"Bob", "las... @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: -```shell +```bash (rdb:1) next /PathTo/project/app/models/author.rb:12 @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 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 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. -```shell +```bash (rdb:5) info breakpoints Num Enb What 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.. -```shell +```bash (rdb:5) delete 1 (rdb:5) info 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+: -```shell +```bash set autolist set forcestep 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: -```shell +```bash $ gem install bleak_house ``` @@ -660,13 +660,13 @@ require 'bleak_house' if ENV['BLEAK_HOUSE'] Start a server instance with BleakHouse integration: -```shell +```bash $ 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+: -```shell +```bash ** BleakHouse: working... ** BleakHouse: complete ** 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: -```shell +```bash 191691 total objects Final heap size 191691 filled, 220961 free Displaying top 20 most common line/class pairs diff --git a/guides/source/engines.md b/guides/source/engines.md index 25321d76eaf..bd7b3ec25e0 100644 --- a/guides/source/engines.md +++ b/guides/source/engines.md @@ -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: -```shell +```bash $ rails plugin new blorgh --full --mountable ``` The full list of options for the plugin generator may be seen by typing: -```shell +```bash $ 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: -```shell +```bash 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. -```shell +```bash $ rails generate scaffold post title:string text:text ``` This command will output this information: -```shell +```bash invoke active_record create db/migrate/[timestamp]_create_blorgh_posts.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. -```shell +```bash $ rails generate model Comment post_id:integer text:text ``` This will output the following: -```shell +```bash invoke active_record create db/migrate/[timestamp]_create_blorgh_comments.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: -```shell +```bash $ rails g controller comments ``` This will generate the following things: -```shell +```bash create app/controllers/blorgh/comments_controller.rb invoke erb 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: -```shell +```bash $ 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: -```shell +```bash $ rake blorgh:install:migrations ``` If you have multiple engines that need migrations copied over, use +railties:install:migrations+ instead: -```shell +```bash $ 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: -```shell +```bash Copied migration [timestamp_1]_create_blorgh_posts.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+: -```shell +```bash 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: -```shell +```bash 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: -```shell +```bash 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: -```shell +```bash $ 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: -```shell +```bash $ 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: -```shell +```bash $ rake db:migrate ``` diff --git a/guides/source/generators.md b/guides/source/generators.md index e9c1b851003..0581af2c854 100644 --- a/guides/source/generators.md +++ b/guides/source/generators.md @@ -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+: -```shell +```bash $ rails new myapp $ cd myapp $ 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: -```shell +```bash $ 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: -```shell +```bash $ rails generate initializer ``` Before we go on, let's see our brand new generator description: -```shell +```bash $ rails generate initializer --help ``` @@ -83,7 +83,7 @@ Creating Generators with Generators Generators themselves have a generator: -```shell +```bash $ rails generate generator initializer create lib/generators/initializer 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): -```shell +```bash $ rails generate initializer --help Usage: rails generate initializer NAME [options] @@ -131,7 +131,7 @@ end And let's execute our generator: -```shell +```bash $ 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: -```shell +```bash rails/generators/initializer/initializer_generator.rb generators/initializer/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: -```shell +```bash $ rails generate scaffold User name:string invoke active_record 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: -```shell +```bash $ rails generate generator rails/my_helper ``` @@ -235,7 +235,7 @@ end We can try out our new generator by creating a helper for users: -```shell +```bash $ rails generate my_helper products ``` @@ -261,7 +261,7 @@ end and see it in action when invoking the generator: -```shell +```bash $ rails generate scaffold Post body:text [...] 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: -```shell +```bash $ rails generate scaffold Comment body:text invoke active_record 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: -```shell +```bash $ 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: -```shell +```bash $ rails new thud -m https://gist.github.com/722911.txt ``` diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index 66193672e48..67a09b6cbda 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -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: -```shell +```bash # 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: -```shell +```bash $ 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: -```shell +```bash $ 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: -```shell +```bash $ 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: -```shell +```bash $ 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: -```shell +```bash $ rails generate controller welcome index ``` Rails will create several files and a route for you. -```shell +```bash create app/controllers/welcome_controller.rb route get "welcome/index" 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: -```shell +```bash $ 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. To create the new model, run this command in your terminal: -```shell +```bash $ 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: -```shell +```bash $ rake db:migrate ``` Rails will execute this migration command and tell you it created the Posts table. -```shell +```bash == CreatePosts: migrating ==================================================== -- create_table(:posts) -> 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 received an error before. -```shell +```bash # rake routes 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 declared before are still available: -```shell +```bash # rake routes posts GET /posts(.:format) posts#index 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 reference of post comments. Run this command in your terminal: -```shell +```bash $ 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 column. Go ahead and run the migration: -```shell +```bash $ rake db:migrate ``` 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: -```shell +```bash == CreateComments: migrating ================================================= -- create_table(:comments) -> 0.0008s @@ -1362,7 +1362,7 @@ In":routing.html guide. 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: -```shell +```bash $ rails generate controller Comments ``` diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md index 7575addf5e8..75be7e6c682 100644 --- a/guides/source/layouts_and_rendering.md +++ b/guides/source/layouts_and_rendering.md @@ -109,7 +109,7 @@ render :nothing => true 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 HTTP/1.1 200 OK Connection: close @@ -601,7 +601,7 @@ head :bad_request This would produce the following header: -```shell +```bash HTTP/1.1 400 Bad Request Connection: close Date: Sun, 24 Jan 2010 12:15:53 GMT @@ -620,7 +620,7 @@ head :created, :location => photo_path(@photo) Which would produce: -```shell +```bash HTTP/1.1 201 Created Connection: close Date: Sun, 24 Jan 2010 12:16:44 GMT diff --git a/guides/source/migrations.md b/guides/source/migrations.md index 2c02e28c8dd..fde7fecebde 100644 --- a/guides/source/migrations.md +++ b/guides/source/migrations.md @@ -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 adding these columns will also be created. For example, running -```shell +```bash $ 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 to an existing table) then you can also use the migration generator: -```shell +```bash $ 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 appropriate +add_column+ and +remove_column+ statements will be created. -```shell +```bash $ rails generate migration AddPartNumberToProducts part_number:string ``` @@ -293,7 +293,7 @@ end Similarly, -```shell +```bash $ rails generate migration RemovePartNumberFromProducts part_number:string ``` @@ -313,7 +313,7 @@ end You are not limited to one magically generated column. For example -```shell +```bash $ 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 -```shell +```bash $ rails generate migration AddUserRefToProducts user:references ``` @@ -366,7 +366,7 @@ following modifiers: For instance, running -```shell +```bash $ 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 to version 20080906120000 run -```shell +```bash $ 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 number associated with the previous migration you can run -```shell +```bash $ rake db:rollback ``` This will run the +down+ method from the latest migration. If you need to undo several migrations you can provide a +STEP+ parameter: -```shell +```bash $ 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 if you need to go more than one version back, for example -```shell +```bash $ 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 example, -```shell +```bash $ 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. A migration creating a table and adding an index might produce output like this -```shell +```bash == CreateProducts: migrating ================================================= -- create_table(:products) -> 0.0028s @@ -749,7 +749,7 @@ end generates the following output -```shell +```bash == CreateProducts: migrating ================================================= -- Created a table -> and an index! diff --git a/guides/source/performance_testing.md b/guides/source/performance_testing.md index c2462adf952..0b9429260b0 100644 --- a/guides/source/performance_testing.md +++ b/guides/source/performance_testing.md @@ -53,7 +53,7 @@ the application's homepage. Rails provides a generator called +performance_test+ for creating new performance tests: -```shell +```bash $ 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: -```shell +```bash $ rake test:benchmark ``` @@ -194,7 +194,7 @@ test case is run *once* in profiling mode. To run performance tests in profiling mode: -```shell +```bash $ 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: -```shell +```bash BrowsingTest#test_homepage (31 ms warmup) wall_time: 6 ms 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+: -```shell +```bash 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.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: -```shell +```bash BrowsingTest#test_homepage (58 ms warmup) process_time: 63 ms 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 tests will set the following configuration parameters: -```shell +```bash ActionController::Base.perform_caching = true ActiveSupport::Dependencies.mechanism = :require 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 patched Ruby interpreter: -```shell +```bash $ rvm install 1.9.2-p180 --patch gcdata $ rvm install 1.8.7 --patch ruby187gc $ 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 one: -```shell +```bash $ 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-gcdata # your patched ruby @@ -464,7 +464,7 @@ Ruby binary inside your home directory. ##### Download and Extract -```shell +```bash $ mkdir rubygc $ wget $ tar -xzvf @@ -473,7 +473,7 @@ $ cd ##### 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.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 +<homedir>+ with a full patch to your actual home directory. -```shell +```bash $ ./configure --prefix=//rubygc $ make && make install ``` @@ -493,7 +493,7 @@ $ make && make install For convenience, add the following lines in your +~/.profile+: -```shell +```bash alias gcruby='~/rubygc/bin/ruby' alias gcrake='~/rubygc/bin/rake' alias gcgem='~/rubygc/bin/gem' @@ -525,7 +525,7 @@ performance testing: Usage: -```shell +```bash Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS] -r, --runs N Number of runs. Default: 4 @@ -537,7 +537,7 @@ Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS] Example: -```shell +```bash $ 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: -```shell +```bash Usage: rails profiler 'Ruby.code' 'Ruby.more_code' ... [OPTS] -r, --runs N Number of runs. Default: 1 @@ -559,7 +559,7 @@ Usage: rails profiler 'Ruby.code' 'Ruby.more_code' ... [OPTS] Example: -```shell +```bash $ 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 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] Rendering template within layouts/items 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: -```shell +```bash Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items] ``` diff --git a/guides/source/plugins.md b/guides/source/plugins.md index 93998bf26d1..eecd4014b45 100644 --- a/guides/source/plugins.md +++ b/guides/source/plugins.md @@ -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 and options by asking for help: -```shell +```bash $ rails plugin --help ``` @@ -53,7 +53,7 @@ You can navigate to the directory that contains the plugin, run the +bundle inst You should see: -```shell +```bash 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: -```shell +```bash 1) Error: test_to_squawk_prepends_the_word_squawk(CoreExtTest): 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. -```shell +```bash 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: -```shell +```bash $ rails console >> "Hello World".to_squawk => "squawk! Hello World" @@ -191,7 +191,7 @@ end When you run +rake+, you should see the following: -```shell +```bash 1) Error: test_a_hickwalls_yaffle_text_field_should_be_last_squawk(ActsAsYaffleTest): 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 test/dummy directory: -```shell +```bash $ cd test/dummy $ rails generate model Hickwall last_squawk: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 and migrating the database. First -```shell +```bash $ cd test/dummy $ rake db:migrate $ 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+. -```shell +```bash 1) Error: test_a_hickwalls_yaffle_text_field_should_be_last_squawk(ActsAsYaffleTest): NoMethodError: undefined method `yaffle_text_field' for # @@ -309,7 +309,7 @@ ActiveRecord::Base.send :include, Yaffle::ActsAsYaffle When you run +rake+ you should see the tests all pass: -```shell +```bash 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: -```shell +```bash 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: -```shell +```bash $ rake rdoc ``` diff --git a/guides/source/rails_application_templates.md b/guides/source/rails_application_templates.md index c03eb1d0bee..b28c8d5e20c 100644 --- a/guides/source/rails_application_templates.md +++ b/guides/source/rails_application_templates.md @@ -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. -```shell +```bash $ rails new blog -m ~/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. -```shell +```bash $ rake rails:template LOCATION=~/template.rb $ rake rails:template LOCATION=http://example.com/template.rb ``` diff --git a/guides/source/rails_on_rack.md b/guides/source/rails_on_rack.md index 22502c9d544..8fe10026a5e 100644 --- a/guides/source/rails_on_rack.md +++ b/guides/source/rails_on_rack.md @@ -85,13 +85,13 @@ run ApplicationName::Application And start the server: -```shell +```bash $ rackup config.ru ``` To find out more about different +rackup+ options: -```shell +```bash $ 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: -```shell +```bash $ 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. -```shell +```bash $ rake middleware (in /Users/lifo/Rails/blog) use ActionDispatch::Static diff --git a/guides/source/routing.md b/guides/source/routing.md index 96f9bc03c2e..28afcfcc280 100644 --- a/guides/source/routing.md +++ b/guides/source/routing.md @@ -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: -```shell +```bash $ CONTROLLER=users rake routes ``` diff --git a/guides/source/testing.md b/guides/source/testing.md index 68bd8941bd0..878e2eeb877 100644 --- a/guides/source/testing.md +++ b/guides/source/testing.md @@ -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: -```shell +```bash $ ls -F test fixtures/ functional/ integration/ performance/ test_helper.rb unit/ @@ -123,7 +123,7 @@ NOTE: For more information on Rails scaffolding, 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: -```shell +```bash $ rails generate scaffold post title:string body:text ... 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: -```shell +```bash $ rake db:migrate ... $ 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: -```shell +```bash $ ruby -Itest test/unit/post_test.rb 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+. -```shell +```bash $ ruby -Itest test/unit/post_test.rb -n test_the_truth Loaded suite unit/post_test @@ -262,7 +262,7 @@ end Let us run this newly added test. -```shell +```bash $ ruby unit/post_test.rb -n test_should_not_save_post_without_title Loaded suite -e Started @@ -287,7 +287,7 @@ end Running this test shows the friendlier assertion message: -```shell +```bash 1) Failure: test_should_not_save_post_without_title(PostTest) [/test/unit/post_test.rb:6]: Saved the post without a title. @@ -304,7 +304,7 @@ end 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 Loaded suite unit/post_test Started @@ -330,7 +330,7 @@ end 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 Loaded suite -e 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. -```shell +```bash $ rails generate integration_test user_flows exists test/integration/ create test/integration/user_flows_test.rb