|
|
|
# Events
|
|
|
|
Events in Project Forum are used to keep a track record of who did what (log) and as a way to create [Notifications](Notifications) (a notification requires an event).
|
|
|
|
|
|
|
|
## Using events
|
|
|
|
The concern `Notifyable` can be included to get access to the `log_event` and `log_event_with_user` methods. The `log_event` method is intended to be used from controllers, while the `log_event_with_user` can be used from any class.
|
|
|
|
|
|
|
|
For example, from a controller you may see the following:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
class SomeController < ApplicationController
|
|
|
|
include Notifyable
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
def someMethod
|
|
|
|
log_event(
|
|
|
|
@something,
|
|
|
|
:create,
|
|
|
|
{ something_else: 'Store this for use in the message under a specific key' }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
### log_event
|
|
|
|
Logs a new event on the given resource of the given action triggered by the current_user.
|
|
|
|
> This method is intended for use from controllers. See `log_event_with_user` for usage outside controllers.
|
|
|
|
|
|
|
|
* @param resource [ApplicationRecord] the resource on which the event occurred. If not specified, resource_type is instead set to `controller_name` (i.e. `ProjectsController` -> `project`)
|
|
|
|
* @param action [Symbol, String] the action which occurred on resource. If not specified, the invoked action of the controller is used (`action_name`, i.e. index/show/new/edit/destroy/create).
|
|
|
|
* @param message_parameters [Hash] parameters related to the event (specifically the message)
|
|
|
|
* @return [Event]
|
|
|
|
```ruby
|
|
|
|
def log_event(resource = nil, action = nil, message_parameters = {})
|
|
|
|
```
|
|
|
|
|
|
|
|
### log_event_with_user
|
|
|
|
Logs a new event on the given resource of the given action triggered by the given user.
|
|
|
|
|
|
|
|
* @param resource [ApplicationRecord, String] the resource or resource_type on which the action occurred
|
|
|
|
* @param action [Symbol, String] the action which occurred on resource
|
|
|
|
* @param user [User] the user who triggered the event
|
|
|
|
* @param message_parameters [Hash] parameters related to the event (specifically the message)
|
|
|
|
* @return [Event]
|
|
|
|
```ruby
|
|
|
|
def log_event_with_user(resource, action, user, message_parameters = {})
|
|
|
|
``` |
|
|
|
\ No newline at end of file |