【问题标题】:rails the best way to saving page duration and page loading speedrails 节省页面持续时间和页面加载速度的最佳方法
【发布时间】:2012-10-13 13:10:59
【问题描述】:

您好,我是 Rails 的初学者,但我的英语不太好。所以如果有一些完全的废话,请理解..

我正在尝试记录每个页面的加载速度和页面持续时间。 我在我的“页面”模型中创建了一个数据库“页面”和方法“保存页面”。 为了保存在每个页面中,我在应用程序控制器中放置了“savepage”方法。

页面.rb

def self.savepage
    .
    .
    .
end

application_controller.rb

before_filter :dosave
def dosave
    Page.savepage
end

这种格式..

我的问题是 1.我做对了吗?使用 before_filter 在加载过程的第一个过程中进行保存? 2. 加载页面中的所有内容后保存我应该使用什么? 3. 用户离开这个页面后保存应该用什么?

我看到了 before_destroy 和 after_filter,但是我找不到它是什么……过滤器是什么意思……什么动作意味着销毁…… 提前谢谢你!

【问题讨论】:

    标签: ruby-on-rails before-filter


    【解决方案1】:

    before_filter 是在向控制器发出请求之前加载的第一件事。但是您的需求完全不同。从根本上过滤器使用布尔检查。如果某些方法为真,它将运行,否则它可能不会。此过滤器进一步扩展,我们将代码放入该过滤器中。(甚至有时它被认为是最佳实践)。

    现在,before_filter :dosave 可能是正确的它不是了解页面(UI)加载过程的真实方式。我建议您使用 javascript 调用或使用一些手动创建的辅助方法并将其放入查看 .erb 文件中。

    你可能会对此感兴趣
    https://github.com/grosser/record_activities
    Log user activities in ROR

    动作是什么意思?

    Action Controller is the C in MVC. After routing has determined which controller to use for a request, your controller is responsible for making sense of the request and producing the appropriate output. Luckily, Action Controller does most of the groundwork for you and uses smart conventions to make this as straightforward as possible.
    来源:http://guides.rubyonrails.org/action_controller_overview.html 我强烈建议您阅读上述文档。这对你来说是非常必要的,它涵盖了你在这里问的话题。` 还有一件事,

    什么是动作破坏?

    这只是一个简单的操作方法,就像 new 一样。因为,rails 遵循Convention over configuration(以及它的开发人员)所以他们放置了一些代码来做一些deletedestroy 或一些破坏。这让事情变得简单,否则将需要更多配置,这违反了 Rails 策略。

    【讨论】:

      猜你喜欢
      • 2013-06-27
      • 1970-01-01
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 2010-12-22
      • 1970-01-01
      • 2018-02-25
      • 1970-01-01
      相关资源
      最近更新 更多