public-activity / public_activity Goto Github PK
View Code? Open in Web Editor NEWEasy activity tracking for models - similar to Github's Public Activity
License: MIT License
Easy activity tracking for models - similar to Github's Public Activity
License: MIT License
Following discussion in #55 lets setup a mailing list/google plus group and encourage people to ask there instead of opening tickets every time things do not work.
Thanks.
You may wish to avoid using cattr_accessor to store current_user. Weird things could happen due to threading issues.
Here's one possible solution:
http://coderrr.wordpress.com/2008/04/10/lets-stop-polluting-the-threadcurrent-hash/
But again may not be 100% safe depending on the Ruby interpreter.
I use ruby 1.9.3-p362 with rails 3.2.11, when I create an activity with owner or recipient, the owner and recipient fields still leaves blank.
1.9.3p362 :001 > pos = Post.first
Post Load (0.3ms) SELECT posts
.* FROM posts
LIMIT 1
=> #<Post id: 1, title: "A Guide To Create New Language", content: "Hello World!", created_at: "2013-01-14 07:57:34", updated_at: "2013-01-14 07:57:34">
1.9.3p362 :003 > pos.create_activity key: "some key", recipient: User.first
User Load (0.4ms) SELECT users
.* FROM users
LIMIT 1
(0.2ms) BEGIN
SQL (0.6ms) INSERT INTO activities
(created_at
, key
, owner_id
, owner_type
, parameters
, recipient_id
, recipient_type
, trackable_id
, trackable_type
, updated_at
) VALUES ('2013-01-14 09:01:27', 'some key', NULL, NULL, '--- {}\n', NULL, NULL, 1, 'Post', '2013-01-14 09:01:27')
(52.1ms) COMMIT
=> nil
and my model as following:
class Post < ActiveRecord::Base
attr_accessible :content, :title
include PublicActivity::Model
tracked
end
class User < ActiveRecord::Base
attr_accessible :email, :nick_name
end
~
Should private notifications use joint table or just multiply records for every user?
I added the attribute name archive to a table. If I add "archive" to params, the server will show too deep stack error. I have change its name to deleted_question, it works fine.
Error:
ruby tracked owner: Proc.new{ |controller, model| controller.current_user }, params: { archive: :archive}
Work:
ruby tracked owner: Proc.new{ |controller, model| controller.current_user }, params: { deleted_question: :deleted_question}
Hi, I'm on latest released rails with public_activity
from master
. I get the following warnings when using/testing public_activity:
...
DEPRECATION WARNING: You're trying to create an attribute `recipient_type'. Writing arbitrary attributes on a model is deprecated. Please just use `attr_writer` etc. (called from create_activity at /home/stas/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/bundler/gems/public_activity-911c4190580e/lib/public_activity/common.rb:84)
...
Since v0.4.0 is not released, thought you can take a look.
Thanks in advance.
Hi,
Im using Rails 3.2.7 and Ruby 1.9.3 but keep getting this error
Routing Error
uninitialized constant PublicActivity::Model
I have followed all the instructions on how to add this to a model but cant get it to work. Any ideas what it could be?
Thanks
Hello,
first of all - thank you for creating this amazing gem, you saved me a lot of work and i really appreciate it :)
Anyway, i have a small problem. I'm creating an app - let's call it an online restaurants catalogue. There are two models: Spot
and City
What i need to do is to be able to display an activity stream on single Spot's profile but i also want to display activity streams on City's profiles (activity streams of spots which belongs to this city, not city's streams itself). Offcourse i can use params
parameter for create_activity
method when tracking Spot
activity but it would be probably not quite optimal to query City's activity using SQL LIKE
statements (they are quite heavy, right?). I decided it would better to add a column to activities
table in which i will keep the city ID.
Is there any way to use custom table columns without hacking a public_activity
source code ? Unfortunatelly, this code won't work:
@spot.create_activity key: 'spot.update', city_id: @spot.city.id
Thank you for any help!
create、update、destroy and so on
This is more like an open question.
I need a way to reduce the amount of repetitive activities so that if I get same keys for the same object, I could develop a strategy to map/merge those into a single entry.
Ideally I would patch public_activity
to handle that for me. Anyone interested in getting something like this into the core or I should not even bother pitching this.
Thanks
MacBook-Pro:atelier chussenot$ rake db:migrate
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in PublicActivity::Tracked instead. (called from include at /Users/chussenot/.rvm/gems/ruby-1.9.2-p290@atelier/gems/public_activity-0.3.2/lib/public_activity.rb:51)
We use Pusher and public_activity in a Rails app where all our live updates need to be kept private, and only shown to the users who are meant to see them.
I just saw that the current stable version of public_activity has Pusher as a dependency - good idea in principle, but unfortunately (correct me if I'm wrong) I think it pushes every activity on any tracked model onto the public activity-channel
.
Since anyone could subscribe to this channel this kinda ruins our plans for keeping the updates private :P
Is this fixed in #12, i.e. the Pusher integration will be completely disabled unless we explicitly turn it on?
Is it possible to add to the readme an example of tracking a custom action from a controller?
or pointing to a page that describes it. I find it difficult to handle the docs without a particular order to learn it..
your gem is really amazing but I am intermediate rails developer..I am using rails 3.2.1 and ruby 1.8.7..In my Post model ,,which belongs to User ,,I need to get the the post owner and created_at in the activity
regards
Hi,
I am trying to run a functional test with public activity tracking enabled (i need to include it in my test), but I am getting the following error, since conroller is nil:
NoMethodError: undefined method current_user' for nil:NilClass app/models/photo.rb:97:in
block in class:Photo'
test/functional/api/v1/photos_controller_test.rb:22:in `block in class:PhotosControllerTest'
Here is the code on line 97 of photo.rb
include PublicActivity::Model
tracked :owner => proc { |controller, model|
controller.current_user
}
The system works great when running in dev or prod environments.
Could you help?
thanks a lot for this great gem,
thimios
It will be easier to test smaller parts like the upcoming rendering with templates.
I've been looking around quite a bit for something akin to Facebook Notifications. I think Public Activity could do this with a few simple changes.
I think that is basically it. I would be willing to take a stab at these changes if you are on board with them but I didn't want to add them if they wouldn't end up in master.
Hi guys,
This commit f2bc223 probably solves the camel-case naming issue, but it breaks the namespaced naming classes compatibility.
Keys for namespaces now look like this: my_engine/model.action
where it should look like my_engine_model.action
.
Is there a way to turn off tracking of models while runing rake db:seed?
thanks a lot
When using (include PublicActivity::Model with tracked), everything works fine. However, for a model where I only wish to record custom activities, and use (include PublicActivity::Common without tracked), I get error messages which references "create_activity" line with following error:
undefined method `public_activity_enabled?' for #< ..model object id...>
My create_activity statement is inside one of the model methods and looks like this:
create_activity(:schedule, :owner => creator, :recipient => account, :params => {:username => self.creator.username})
Since pusher is optional, it would be nice to make it a soft dependency and just mention it in the documentation if people really want to use it.
Thanks.
I add the code below to assign owner, but RSpec cannot detect current_user.
class Article < ActiveRecord::Base
tracked owner: Proc.new{ |controller, model| controller.current_user }
end
Do you have any solutions?
I want to relize a simple activity feed in my project.
Is it possible to use mongoid with your gem?
Is it possible to track the index and destroy action with the current version?
Hi, I'm getting warnings when activities are created.
DEPRECATION WARNING: You're trying to create an attribute
recipient_id'. Writing arbitrary attributes on a model is deprecated. Please just use attr_writer
etc. (called from create_activity at /home/rayko/.rvm/gems/ruby-1.9.3-p0@app/bundler/gems/public_activity-efcf74abb8f6/lib/public_activity/common.rb:84)
DEPRECATION WARNING: You're trying to create an attribute recipient_type'. Writing arbitrary attributes on a model is deprecated. Please just use
attr_writer etc. (called from create_activity at /home/rayko/.rvm/gems/ruby-1.9.3-p0@app/bundler/gems/public_activity-efcf74abb8f6/lib/public_activity/common.rb:84)
I've updated public_activity to 0.5 and still have the warnings. I also ran the migration, when I updated from 0.3.3 to 0.3.4 though, and the 0.5 upgrade migration is just the same I already run back then, so I guess it wasn't necesary to re-run it. Also I'm using Rails 3.2.2
Hi
Great gem.
In revision 5d5859c (1.0.0), I get an unitialized constant error. I think it has to do with the ORM support that you put in but I wasn't able to diagnose it further/fix it unfortunately. Stack trace is below.
For now, I'll back up a version or two, but wanted to let you know.
Thanks.
rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
uninitialized constant PublicActivity::Model::Trackable
/Users/gary/.rvm/gems/ruby-1.9.3-p194/bundler/gems/public_activity-5d5859c40feb/lib/public_activity.rb:47:in block in <module:Model>' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/concern.rb:119:in
class_eval'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/concern.rb:119:in append_features' /Users/gary/Source/myapp/app/models/user.rb:12:in
include'
/Users/gary/Source/myapp/app/models/user.rb:12:in <class:User>' /Users/gary/Source/myapp/app/models/user.rb:1:in
<top (required)>'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in block in constantize' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in
each'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in constantize' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext/string/inflections.rb:54:in
constantize'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/bundler/gems/forem-03725d78827c/lib/forem.rb:37:in rescue in user_class' /Users/gary/.rvm/gems/ruby-1.9.3-p194/bundler/gems/forem-03725d78827c/lib/forem.rb:34:in
user_class'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/bundler/gems/forem-03725d78827c/lib/forem/user_class_extensions.rb:2:in <top (required)>' /Users/gary/.rvm/gems/ruby-1.9.3-p194/bundler/gems/forem-03725d78827c/lib/forem/engine.rb:17:in
block in class:Engine'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:429:in _run__3923762982401776762__prepare__602551583965757566__callbacks' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in
__run_callback'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in _run_prepare_callbacks' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in
run_callbacks'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/reloader.rb:74:in prepare!' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/reloader.rb:48:in
prepare!'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application/finisher.rb:47:in block in <module:Finisher>' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:30:in
instance_exec'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:30:in run' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:55:in
block in run_initializers'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:54:in each' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:54:in
run_initializers'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application.rb:136:in initialize!' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in
method_missing'
/Users/gary/Source/myapp/config/environment.rb:5:in <top (required)>' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application.rb:103:in
require_environment!'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application.rb:295:in block (2 levels) in initialize_tasks' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:228:in
call'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:228:in block in execute' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:223:in
each'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:223:in execute' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:166:in
block in invoke_with_call_chain'
/Users/gary/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:159:in
invoke_with_call_chain'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:187:in block in invoke_prerequisites' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:185:in
each'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:185:in invoke_prerequisites' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:165:in
block in invoke_with_call_chain'
/Users/gary/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:159:in
invoke_with_call_chain'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/task.rb:152:in invoke' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/application.rb:143:in
invoke_task'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/application.rb:101:in block (2 levels) in top_level' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/application.rb:101:in
each'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/application.rb:101:in block in top_level' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/application.rb:110:in
run_with_threads'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/application.rb:95:in top_level' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/application.rb:73:in
block in run'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/application.rb:160:in standard_exception_handling' /Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/lib/rake/application.rb:70:in
run'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/gems/rake-10.0.3/bin/rake:33:in <top (required)>' /Users/gary/.rvm/gems/ruby-1.9.3-p194/bin/rake:23:in
load'
/Users/gary/.rvm/gems/ruby-1.9.3-p194/bin/rake:23:in `
In github stream get activities presented like so "bjensen commented on issue 114 on eternicode/bootstrap-datepicker 8 days ago"
Setting the owner is obvious with this gem, but how would one set the parent, in this issue: 'eternicode/bootstrap-datepicker' ?
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in PublicActivity::Tracked instead. (called from <top (required)> at /Users/alec/Documents/Projects/RailsApps/progressorapp/config/application.rb:13)
Example:
model: my_model
tree: public_activity/my_model
After a while i found out that the layout helper expects a tree "public_activity/mymodel" because the :key is named "mymodel".
I've added
class Post< ActiveRecord::Base
include PublicActivity::Model
tracked
but when I look at PublicActivity::Activity I see that owner_id and type is nil.
the create action for Post has
@post=current_user.posts.new(params[:post])
if @post.save
....
shouldn't the activity should set its owner to current_user?
After upgrading an application to rc1, I have been receiving the following error:
undefined method `get_controller' for PublicActivity:Module
This error is being thrown after the render_activity helper is called and only happens when there are Activity records within the database.
I can provide more details about my application or the stack trace if needed.
It would be a way to record custom activities in a convenient way, preserving configuration of global params, and hooks.
I am using rails 3.2.11 and i keep getting the following error when trying to create an activity
undefined method `public_activity_enabled?' for #Product:0xb439134
my model is like this
class Product < ActiveRecord::Base
include Authority::Abilities
include ApprovableModel
include PublicActivity::Common
#tracked :owner => proc {|controller, model| controller.current_administrator}
has_many :product_models, :dependent => :destroy
attr_accessible :name
validates :name, :presence => true, :uniqueness => true
end
and my controller update action is below
def update
@Product = Product.find(params[:id])
if @product.update_attributes(params[:product])
redirect_to business_products_url, notice: 'Product was successfully updated.'
@product.create_activity(:update, :owner => current_administrator)
else
render action: "edit"
end
end
any help. Thanks
We need to provide a filter for ActionController to give PublicActivity reference to currently running controller. Use of Thread.current[]=
. This will ease up how parameters are built up without explicit instructions in controllers.
Hi,
My app is using devise but I cant seem to get it to set the owner_id, Is there anything special I need to do?
have tried the below in my model
include PublicActivity::Model
tracked :owner => @current_user
include PublicActivity::Model
tracked :params => {:owner_id => @current_user}
any help would be appreciated, thanks in advance.
Tried installing and running the gem within a Rails 3.0 app and it throws an error of 'Template not defined' even though I created an initializer which loads the path of the yaml file?
Are there any plans for supporting custom user activities in the future? Another nice feature might be to specify exactly what actions your want to track as opposed to Create, Update, Delete which might not even be used.
In the example, you used pusher in the activity_obeserver; is that specifically needed for it to work. I don't think so, but I can't get things to show in the view!
Attempt to create new tracked record causes error "ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: key, owner, parameters)"
I think I might be missing something but is there a way to add default params to my model - I need every activity to have an account_id for scoping. Is this possible?
We would like to be able to configure the tracked
ActiveRecord hooks to determine whether or not an activity should be created.
In our case, we have a tracked
model where we only want to create a corresponding Activity record if certain attributes were changed, but not others.
Could this be done as a block passed to the tracked
method, or an options hash of some kind?
The trick here is discarding attributes in lambdas, like so:
# if we want to build a param from model, we'd use
tracked :params => {:article_name => lambda { |_, model| model.name } }
# and if we'd want to build a param from controller:
tracked :author => lambda { |controller, _| controller.current_user.email }
Note: lambda verifies number of parameters passed, so underscores are needed in both cases.
How do I disable default CRUD tracking for a model?
the reason I'm asking is that user.update registered as activity if a user logs in using devise which changes the sign_in_count and date, etc..
How will the gem work on Rails 4 when the observers are being dropped?
will there be support for rails 4?
thanks
Hey any chance you could make the view files from http://public-activity-example.herokuapp.com/feed available? It would be great to see how you have set it up.
If a User model is tracked and the user updates itself (like update settings) the activity that comes out is
#<PublicActivity::Activity id: 7, trackable_id: nil, trackable_type: nil, owner_id: 2, owner_type: "User", key: "user.update", parameters: {}, recipient_id: nil, recipient_type: nil, created_at: "2012-12-24 13:52:06", updated_at: "2012-12-24 13:52:06">
shouldn't trackable id and type be the same as owner in this case?
Why is it nil? is this correct behavior?
In the example [How to] Create custom activities, it puts:
"Besides standard, automatic activities created on CRUD actions on your model (deactivatable), you can post your own activities that..."
The issue is that I haven't seen any clue on how to deactivate those basics activities. I just want to record the custom activities, but don't know how.
Sorry if this doesn't seems like an issue, but I searched for an answer on google and didn't find it. I don't know where else to ask. Thanks in advance!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.