Loading data from database by Ajax - Ruby on Rails app

385 Views Asked by At

Sometimes at websites all comments or other data from DB is hidden by default. When user click at link like "Display comments" all comments from database are dynamically selected and placed under the content. It must be great for mysql performance, because content is generated only when user excatly need it. I would like to implement this stuff at my app.

I've got one idea to do this so far. Remote action with @comments = Content.comments and next page.insert_html at RJS template. Is it good idea or maybe I should choose different way?

1

There are 1 best solutions below

3
On

The decision is purely based on the application that you are developing. For example if in case of stack overflow it does not make sense to show only the question and show answer link. But in case of a blog post it may be fine.

In the above situation, I don't think there will be a good improvement in performance by removing the comments of the content on show page. We can achieve the same functionality by making use of javascript methods. Hide the content on page load and show in on client request.