Window id – sample application
I have created a sample application to demonstrate what we could do if we have a window id and what we suffer if we haven’t. The latter is our current situation.
This is part of the window id concept, I try to promote.
Download the sample application from http://www.laliluna.de/download/browser-feature-sample.zip
You will need Firefox 3, Internetexplorer 8 or Safari 4 to use this sample. It makes use of sessionStorage introduced with HTML 5.
Just for the intererested people:
I typed ramaze create sample in a terminal to create the raw application and just added my code.
Exploring the pitfalls
Modern browsers share cookies – including a session cookie – across all open browser windows and tabulators. This is in most cases what you want. If not you have to login again from every browser window you open on the same website.
The disadvantage is that a web developer can not store data into the session, because multiple browser windows would overwrite each others session values.
You can explore this problem following the failing link in the sample application. Just start to edit two turtles in two browser windows and finish the edit process. You end up with only one turtle being changed.
The following has happened:
- Window A stored turtle ‘Willi’ in the session
- Window B replaced turtle ‘willi’ with ‘Liz’
- Window A changes the name and the age of the turtle stored in the session
- Window A confirms the changes and saves them to the simulated database
- Window A has no changed name and age of ‘Liz’ but not of ‘Willi’ as intended
Exploring the happy sample using the windows id
Navigate to the working example in two different browser tabs. You will see that you can independently edit a turtle.
Installing the prerequisites
Ruby and the rubygems package manager
sudo yum install install ruby rubygems
or to get a full environment
sudo yum install install ruby ruby-devel ruby-irb ruby-libs ruby-rdoc ruby-ri rubygems
Hint: On Debian/Ubuntu you will use aptitude to install ruby.
Ruby is already there. You should update the rubygems package manager. Input in a terminal
sudo gem update --system
Visit http://www.ruby-lang.org/ download and setup.
Visit http://rubygems.org/ download and install the ruby package manager.
Inside of a terminal execute the ruby gems package manager to install ramaze and its depencies. I used the version 2009-05.
Sample for Mac and Linux
sudo gem install ramaze
Start the application
cd pathToSample ruby start.rb
Open your browser and navigate to http://localhost:7000/