跟踪用户的示例。
application_controller.rb
class ApplicationController < ActionController::Base
include PublicActivity::StoreController
[.....]
# Only if devise is not used
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
end
活动控制器.rb
class ActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc")
end
end
用户.rb
class User < ActiveRecord::Base
include PublicActivity::Common
[...]
end
users_controller.rb
class UsersController < ApplicationController
def my_method
[...]
respond_to do |format|
if @my_object.save
@my_object.create_activity :create, owner: current_user
[...]
end
end
应用程序/视图/活动/index.html.haml
- @activities.each do |a|
= render_activity a
其他意见
/app
/views
/public_activity
/user
_create.html.haml
_destroy.html.haml
[_all_methods.html.haml]
查看示例
= a.owner.name + " " + a.owner.firstname
created the user
= a.trackable.name + " " + a.trackable.firstname + " (" + a.trackable.email + ")"