Tip #25 - Logging is your friend...
Tue Jun 24 07:18:17 -0700 2008
Sometimes when you need someone to just look over your code and figure out what the heck is going on, you can turn to your best coding friend, this friend sits away in the log directory carefully collecting data waiting for your beck and call…
Watch your log files.
This should sort of be obvious, but I know several people (including yours truly) who have been bitten by this one.
When you are running your specifications, keep a ‘tail -f log/test.log’ running. If you are on Windows and can’t do this, then either install cygwin so that you can, or make your system dual boot with Ubuntu or something so you can.
The logs will tell you a huge amount about what your app is trying to do when. This is especially true if you get a controller spec response along the lines of:
1 2 3 4 5 6 7 8 9 10 11 |
1) 'PeopleController handling GET /people should render index template' FAILED expected "index", got nil ./spec/controllers/people_controller_spec.rb:54: script/spec:4: 2) 'PeopleController handling GET /people/new should render new template' FAILED expected "new", got nil ./spec/controllers/people_controller_spec.rb:60: script/spec:4: |
I expected the new template, but got nil… not very helpful…
But in the logs, the truth appears:
1 2 3 4 5 6 7 8 9 10 11 |
Processing PeopleController#index (for 0.0.0.0 at 2008-06-25 09:15:28) [GET]
Session ID:
Parameters: {"action"=>"index", "controller"=>"people"}
Filter chain halted as [:must_login] rendered_or_redirected.
Completed in <snip> | 200 OK [http://test.host/people]
Processing PeopleController#index (for 0.0.0.0 at 2008-06-25 09:15:28) [GET]
Session ID:
Parameters: {"action"=>"new", "controller"=>"people"}
Filter chain halted as [:must_login] rendered_or_redirected.
Completed in <snip> | 200 OK [http://test.host/people] |
Ahh! Filter chain halted as the must_login method returned false! So we forgot to log in before we went to try and get the controller action.
Simple example, I know… but aren’t all the good tips simple?
Mikel
Latest posts
- This Relationship is Worth Nothing
- Thank YOU...
- Inline Attachments for ActionMailer
- Upgrading RailsPlugins.org to Rails 3 - Part 1
- Stripping dollar signs and commas from a string
- Getting Rails 3 Edge with jQuery, RSpec and Cucumber using RVM
- Action Mailer, go Proc thyself
- The Real News Donation Drive
- ActionMailer ScreenCast and Article
- Installing RSpec for Rails 3
- I am speaking at RailsConf 2010
- Rails 3 Session Secret and Session Store
- If you're lazy and you know it write your specs!
- Bundler - uninitialized constant ActionController
- Bundle Me Some Sanity
- How to use Mail / ActionMailer 3 with GMail SMTP
- Put your mailer where the action is!
- Why Force a Choice?
- How to make an RSS feed in Rails
- Rails 3 Routing with Rack
- Bundle me some Rails
- Helping out in Haiti
- Watch your self
- Is Rails 3.0 a Game Changer?
- Where did the scripts go?
- validates :rails_3, :awesome => true
- New Rails Version 3.0 Guides Online
- New ActionMailer API in Rails 3.0
- Mail gem version 2 released
- How to rename a Rails 3 Application
- Rails 3.0 Examples
- DECCA Driving Day
- Mail now merged into ActionMailer
- Tip #29 - Stop a Mongrel (or any) Service in Windows
- Ruby on Rails Tips Page
- Monitoring a DAHDI or Zaptel Channel
- Mail gets some compliments!
- Rails Unit Tests: uninitialized constant error
- New Mail gem released
- Mail and Bounced Emails
- Mail, TMail, The Future of Ruby Email Handling
- Custom Music on Hold for Asterisk
- Always getting an invalid authenticity token error
- Windows ipconfig does not show anything
- FreeBSD rc scripts
- How to monitor a logged in professional
- TMail Moves to GIT
- Funny...
- How to reset a sequence with PostgreSQL
- OpenBSD RAID and Temp Sensors on HP Proliant DL 360 and 380 Series
Latest comments
- Bala
Hi, This is absolutely nice ...
- Leonid Shevtsov
Your EmailAddress matches "vist...
- Jones Lee
What is the rails3 version of v...
- Emil Kampp
I'm getting this error, when im...
- elberon5
Awesome article thanks! As o...
Categories
Tag Cloud
AJAX ARGH! ActiveRecord Ajax Apache Apple Asterisk Australia Copy Database Development Feedburner Gem server Google Human Rights Javascript L. Ron Hubbard MS SQL Server MacOSX Mail Mephisto Not Programming OpenBSD Opensource Performance Personal Integrity PostgreSQL Programming Prototype Puzzle RDoc REST RESTful Rails RSPec RSpec Rails Rails Tips Rspec Ruby Ruby on Rails Ruby on Rails Tips Ruby on rails Tips SQL SQLServer SVN Scientologist Scientology Site Stats Soekris Soekris net5501 TMail Textmate Tips Windows World about mikel anti drug apache contributing daemon documentation drugs illustrator javascript lambda mail mephisto newspapers nitro open source opensource photoshop productivity programming railscasts rspec ruby ruby on rails rubyforge scientology seo sitemap sqlserver tips tmail tom cruise unix tricks vector graphicsArchives
- November 2009 (1)
- October 2009 (2)
- September 2009 (2)
- August 2009 (0)
- July 2009 (1)
- June 2009 (0)
- May 2009 (1)
- April 2009 (0)
- March 2009 (0)
- February 2009 (0)
- January 2009 (2)
- December 2008 (0)
- November 2008 (5)
- October 2008 (0)
- September 2008 (1)
- August 2008 (0)
- July 2008 (2)
- June 2008 (13)
- May 2008 (7)
- April 2008 (18)
- March 2008 (8)
- February 2008 (5)
- January 2008 (7)
- December 2007 (20)
- November 2007 (22)



Leave a Reply