In practice how ever you want to track all activities in the applications its pretty easy to do this by public_activity gem.here is small implementation of public activity.lets have a look:
To implement public_activity you have to follow these steps
1. Install gem:
install gem by running command 'gem install public_activity' or
write gem 'public_activity' in your gem file and do bundle install.
2. Generate/install migrations:
run command : rails g public_activity:migration
3. Migrate database: run rake db:migrate
4. Model configration:
write following code inside your model
include PublicActivity::Model
tracked
if you want to add owner(creator) of the activity then do this
-> write following code inside your ApplicationController
include PublicActivity::StoreController
-> write following in your model:
include PublicActivity::Model
tracked ,owner: ->(controller, model) { controller && controller.current_user }
5. Skiping actions:
public activity create an record in PublicActivity::Activity on each create/update/destroy of the tracked model if you want to skip any action you can do like this:
include PublicActivity::Model
tracked ,except: [actions]
6.Creating custom activity:
if you want to create a custom activity you can do this:
resource.create_activity :action, owner: current_user
as public_activity track only models that's why if you want to log any other action that not reflect any changes to model then you have to create custom activities according to your requirements.
To implement public_activity you have to follow these steps
1. Install gem:
install gem by running command 'gem install public_activity' or
write gem 'public_activity' in your gem file and do bundle install.
2. Generate/install migrations:
run command : rails g public_activity:migration
3. Migrate database: run rake db:migrate
4. Model configration:
write following code inside your model
include PublicActivity::Model
tracked
if you want to add owner(creator) of the activity then do this
-> write following code inside your ApplicationController
include PublicActivity::StoreController
-> write following in your model:
include PublicActivity::Model
tracked ,owner: ->(controller, model) { controller && controller.current_user }
5. Skiping actions:
public activity create an record in PublicActivity::Activity on each create/update/destroy of the tracked model if you want to skip any action you can do like this:
include PublicActivity::Model
tracked ,except: [actions]
6.Creating custom activity:
if you want to create a custom activity you can do this:
resource.create_activity :action, owner: current_user
as public_activity track only models that's why if you want to log any other action that not reflect any changes to model then you have to create custom activities according to your requirements.
No comments:
Post a Comment