| 67 | | Have "tail -f" commands running on the server.log and development.log. Rails will |
|---|
| 68 | | automatically display debugging and runtime information to these files. Debugging |
|---|
| 69 | | info will also be shown in the browser on requests from 127.0.0.1. |
|---|
| | 67 | Sometimes your application goes wrong. Fortunately there are a lot of tools that |
|---|
| | 68 | will help you debug it and get it back on the rails. |
|---|
| | 69 | |
|---|
| | 70 | First area to check is the application log files. Have "tail -f" commands running |
|---|
| | 71 | on the server.log and development.log. Rails will automatically display debugging |
|---|
| | 72 | and runtime information to these files. Debugging info will also be shown in the |
|---|
| | 73 | browser on requests from 127.0.0.1. |
|---|
| | 74 | |
|---|
| | 75 | You can also log your own messages directly into the log file from your code using |
|---|
| | 76 | the Ruby logger class from inside your controllers. Example: |
|---|
| | 77 | |
|---|
| | 78 | class WeblogController < ActionController::Base |
|---|
| | 79 | def destroy |
|---|
| | 80 | @weblog = Weblog.find(params[:id]) |
|---|
| | 81 | @weblog.destroy |
|---|
| | 82 | logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!") |
|---|
| | 83 | end |
|---|
| | 84 | end |
|---|
| | 85 | |
|---|
| | 86 | The result will be a message in your log file along the lines of: |
|---|
| | 87 | |
|---|
| | 88 | Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1 |
|---|
| | 89 | |
|---|
| | 90 | More information on how to use the logger is at http://www.ruby-doc.org/core/ |
|---|
| | 91 | |
|---|
| | 92 | Also, Ruby documentation can be found at http://www.ruby-lang.org/ including: |
|---|
| | 93 | |
|---|
| | 94 | * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/ |
|---|
| | 95 | * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide) |
|---|
| | 96 | |
|---|
| | 97 | These two online (and free) books will bring you up to speed on the Ruby language |
|---|
| | 98 | and also on programming in general. |
|---|