Rails Troubleshooting Again

In the course of developing a couple themes for the Typo Theme Contest, I ran into some troubles with Typo. Running it locally with Webrick, I kept getting random errors. First, the stylesheet wouldn’t load, or it’d stop loading midway through; then I’d reload the page, and I’d get a random, meaningless error; I’d reload once more and everything would work.

But then it stopped working. I got an error which I didn’t understand, exactly, but which pointed to a problem in the session. Index string something or other.

Generally speaking, if you’re getting wonky behavior from Rails, blowing away the sessions is a good place to start (assuming that simply restarting Webrick doesn’t do the trick—and it didn’t). Ruby on Rails stores its sessions in the file system, so I went to my command-line, typed cd /tmp and looked for the ruby_sess files. They weren’t there. I was mystified.

Then, thankfully, somebody on #rubyonrails reminded me that you can set your sessions to store in the database. If you open environment.rb for Typo, and do a find for “sess,” you’ll see that Typo is one of the apps that does this (and you can see how to do it yourself).

The solution? Log in to the mysql server, select the Typo database, and remove from sessions.

No Comments

  1. johan-s says:

    or run rake purge_sessions_table

    creating the actual session table is as easy as rake create_sessions_table

    Adding an index to the sessid will strongly improve session performance as well.

  2. Eric says:

    Another thing you want to watch out for is if you are running more than one Rails program with file based sessions on. If you are trying to access one and then the other your browser will send the session data from app 1 to app2 which will find the session file but cannot understand the different variables and errors out.

    Clearing the browser will work but I found it is best to just use the database to store sessions. This way the app will only see it’s own session data and will start you fresh on one if you need it.

    Eric

  3. Steve Longdo says:

    I think you mean "delete from sessions;" not "remove from sessions;"…

  4. Amy Hoy says:

    Oy, Steve, you’re right. That’ll teach me to post an article in the last 20 minutes at work before a holiday weekend. Thanks.

    Eric & Johan: thanks for the additional tips. 🙂

  5. Martin says:

    There are some more issues to cope with when using the session storage. Even if you are just a normal visitor on the website a session entry is generated and so this will fill your database and does not provide much sense.

    I found a link how to exclude some pages from the Typo session management.

    http://www.scottstuff.net/blog/articles/2005/11/04/typo-moves-to-rails-0-14-2

    By now this is included in the trunk, but can be added to a normal release as well I think.

  6. It’s good to know that even seasoned rails gurus (would you prefer rails pin up?) stumble too unto things they don’t get.

    I thought I got all these errors because I was on windows and did something wrong as a newbie.

    Thanks Amy!

  7. aidanf says:

    I also experienced problems with existing session cookies when using several different rails applications in the same browser instance. I got around this by installing the firefox web developer extension and do Misc->Clear-session-cookies when moving between rails apps.

  8. Well done, nice instructions 🙁

  9. There is some strange behaviour with this 🙂

  10. Well at last catched the problem…

  11. i am not sure as to why…

  12. I thout to do it in my local version 🙂

  13. Very nice write up!

  14. Open Blouse says:

    Very nice write up!

  15. I had and the fix I found 🙁

  16. There is some strange behaviour with this 🙂

  17. The problem is my browser 🙂

  18. Mover Miami says:

    Thanks for the write-up!

Hey, why not get a shiny
Freckle Time Tracking
account?