Screencast: Notifications in Rails 3

Rails 3 bringt Unterstützung für die Klasse ActiveSupport::Notifications mit und über „subscribe“ kann man über Notifications informiert werden. Ryan stellt in dieser Woche vor wie Notifications eingesetzt werden können.

 

Download:

Download(19.3 MB, 10:22)
Alternativer Download für iPod & Apple TV(17.5 MB, 10:22)

 

Resourcen:

 

Quellcode:

[ruby]
# config/initializers/notifications.rb
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, start, finish, id, payload|
PageRequest.create! do |page_request|
page_request.path = payload[:path]
page_request.page_duration = (finish – start) * 1000
page_request.view_duration = payload[:view_runtime]
page_request.db_duration = payload[:db_runtime]
end
end

ActiveSupport::Notifications.subscribe "products.search" do |name, start, finish, id, payload|
Rails.logger.debug "SEARCH: #{payload[:search]}"
end

# models/product.rb
ActiveSupport::Notifications.instrument("products.search", :search => search)
[/ruby]