通过 Ajax 从数据库加载数据 - Ruby on Rails 应用程序
有时,在网站上,默认情况下会隐藏数据库中的所有评论或其他数据。当用户单击“显示评论”之类的链接时,数据库中的所有评论都会被动态选择并放置在内容下。它对于 mysql 性能一定非常好,因为只有当用户确实需要它时才会生成内容。我想在我的应用程序中实现这些东西。
到目前为止,我有一个想法可以做到这一点。在 RJS 模板中使用 @comments = Content.comments
和下一个 page.insert_html
进行远程操作。这是个好主意还是我应该选择不同的方式?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该决定完全基于您正在开发的应用程序。例如,如果在堆栈溢出的情况下,仅显示问题并显示答案链接是没有意义的。但对于博客文章来说可能没问题。
在上述情况下,我认为去掉展示页内容的评论不会对性能有很好的提升。我们可以通过使用 javascript 方法来实现相同的功能。在页面加载时隐藏内容并根据客户端请求显示。
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.