Please read for an updated status on RailsCasts:
Learn more or hide this
GitHub User: workingBen
I had this issue as well. Move the code into a helper and you'll be good to go. Sorry if that's outdated but if anyone else google's this at least they have an answer.