For my example, I will point you to the Hardcore Racing eStore browse page.
Here’s what happens. The user picks an option from one of the three dropdowns. The busy indicator in the upper right corner immediately appears to show the user something is happening. If not for this, there would be no apparent indication that anything was happening. So, if the operation takes an unusually long time, they might think nothing is happening and try again.
To accomplish this, there are really only three parts, and the first one doesn’t count.
I use a few other libs for this site, but these are the ones you’ll need. Include them between the HEAD tags in the layout template.
Part 2: The View
The view is the RoR template file. Similar to how PHP is embedded, a RoR view (.rhtml file) is html with embedded ruby (erb). Here’s an abridged version of what I’ve used:
Part 3: The Processing Method
Even though it’s a bit outside the scope of this tutorial, I’ll post my browse_next_ajax method here. This method belongs in the controller class, which is the StoreController in my case.
1 2 3 4 5 6 7 8
def browse_next_ajax @cat = Category.find(params[:id]) @cats = @cat.sub_categories if @cat unless @cats && @cats.size > 0 @redirect = true end render :partial => 'browse_next', :layout => false end
Yep, it’s all so simple once you know how. I’m not really sure how easy other frameworks make this sort of thing, but I can’t imagine it could be any easier than this. Ruby on Rails gets two thumbs up.