Tip - When you get a blank screen

Posted by Pat Thu, 19 Jan 2006 10:52:00 GMT

Occasionally when I’m working on an app, I’ll be going along just fine in dev mode. Then I put it up on my production server, and I get an absolute blank page on any request I make. Pisses me off like none other, because I look in the error logs and it’s nothing. I think I’ve figured it out though…just need to remove any existing session info from /tmp or the database.

I just wanted an excuse to post :) I’m working on some paid projects that allow me to write Rails code now, keeping pretty busy..but I need to raise my rates, because I finish way too quickly now.

Tags ,  | no comments

Tip: Future-proofing your app

Posted by Pat Fri, 14 Oct 2005 08:18:00 GMT

I noticed that the Rails book has references to session, flash, params, etc while a lot of the apps you’ll find online use @session, @flash, @params, etc. I went on #rubyonrails to ask what the difference was (other than instance variable vs method call), and it turns out that it’s actually no more complex than instance variable vs method call. I was told that they both work fine for now, but the preferred way of doing this is using the method, and to change the instance variables to method calls to future-proof your app.

Well there are going to be a bajillion references if you’ve got even a moderatly-sized application…so it’s tough. We’ll use the power of FreeBSD’s command line utilities to make it really, really easy.

To save you the trouble of typing all these commands, I created a shell script that you can use. Just download it, drop it in your rails root dir, chmod+x and run it. A description of what it does is below:

Go to your application’s root folder and type:
$find lib app \( -name "*.rb" -o -name "*.rhtml" \) -print0 | xargs -0 sed -i '' -e 's/\@session/session/'
$find lib app \( -name "*.rb" -o -name "*.rhtml" \) -print0 | xargs -0 sed -i '' -e 's/\@flash/flash/'
$find lib app \( -name "*.rb" -o -name "*.rhtml" \) -print0 | xargs -0 sed -i '' -e 's/\@params/params/'
$find lib app \( -name "*.rb" -o -name "*.rhtml" \) -print0 | xargs -0 sed -i '' -e 's/\@request/request/'
$find lib app \( -name "*.rb" -o -name "*.rhtml" \) -print0 | xargs -0 sed -i '' -e 's/\@response/response/'

Okay I don’t want to explain each individual part…but here’s how it goes. First we find all the files in the current directory and all the subdirectories that have a .rb or .rhtml extension, turn them into command line arguments and pass them to sed, which replaces each instance of @session with session.

This only performs the operations on the lib and app directories…those are the only ones that have any of this code besides the tests, I think. Making these changes to the tests will break them, thus the find command only looks for the files in lib/ and app/

Your app ought to work fine after that…I haven’t had any problems so far. Now you’ve got all the nice new method calls instead of the outdated instance variables.

Posted in  | Tags ,  | no comments