Reputation: 548
I am developing a small web application using Ruby, Sinatra & HAML.
The scenario I am struggling with at the moment is something that I used to solve in PHP using Ajax and Javascript, and am not sure how to best go about doing it in Ruby (what the best practice would be, if there is a more optimized way of approaching this).
I have a screen as follows:
What I wish to happen is that when a user clicks on one of the buttons (for example Show most popular), the system calls a function which queries the database to get the relevant records and re-populates the 'Entries' box with the appropriate records. I want to do this without the rest of the page re-loading or anything else being effected, just the 'Entries' box. Bonus - If I can show a little "LOADING" spiral while the data is being fetched.
My research led me to gem known as "typhoeus" which I found to be really great, but am not sure if it applies in this scenario (or how to implement it if it does).
Any kind of help would be greatly appreciated.
Much obliged.
Upvotes: 2
Views: 630
Reputation: 717
It seems like pjax is what you would be looking for.
https://github.com/defunkt/jquery-pjax/tree/heroku
The author uses Sinatra in his example app. Though he does use erb, I am sure that it wouldn't cause any problems if you switched the template engine to haml
Upvotes: 3