Better-than-Google activity indicators with Rails
The next time that you use your GMail account, look on the upper-right corner of the screen when you go from email to email. You'll notice that a red box shows up containing the word "Loading...". This is a very helpful indicator that GMail is in the process of doing something.
Mir.aculo.us has a great article on how to achieve a similar effect using an animated GIF image. You can achieve an even nicer effect by adding partials and Script.aculo.us effects.
First, make sure that the javascripts files are loaded by adding this to the head of your page:
1
| |
This will force the default sets of javascripts files to load. These do include effects.js and application.js.
Next, create a file called application.js under public/javascripts if it doesn't already exists. Add this code:
1
2
3
4
5
6
7
8
9
10
11
| |
Then create a partial called _loading.rhtml:
1
2
3
| |
I also added the following CSS to my application's stylesheet:
1
2
3
4
5
6
7
8
| |
I finally included the partial at the bottom of my layout:
1
| |
From that point on, I got a "loading" indicator each time I clicked on a link created through the link_to_remote helper method. No need to go ahead and add the effects to each invocations.
-- Fred
