public_activity
public_activity copied to clipboard
Feature Request: Option For Single View Template Shared Between Trackables
Currently Public Activity forces a discrete set of views for every Trackable type. In my current project I am using Public Activity to display a simple feed in a CMS. There are 20 separate models, all of which are trackable, and the only thing I want to display is the time the resource was updated/created, a link to the resource, an icon for the resource type and a title. All these resources implement to_title
, so I can use the exact same views for every resource. However Public Activity doesn't allow for this. My only option is to duplicate the exact same views for every resource type.
Please implement some kind of fallback in how Public Activity looks for views. It could start by looking for Model-specific views, then fall back to generic views, much as Rails partials fall back to partials created for a parent controller.
That is a good idea, thanks @1ndivisible.
For now you can use the (undocumented) param :display
, like this:
render_activities(@activities, display: 'generic')
which will use the partial in app/views/public_activity/generic.html.erb
for all activities.
:display
should be a path relative to the app/views/public_activity
directory.
Thanks. This is better, but this doesn't allow for CRUD-specific views(_create.html, _destoy.htnl.erb, update.html.erb), or am I missing something. Obviously I can just use logic in generic,html.erb
but that isn't great.
Quick fix:
In _generic.html.erb
(or bypas display
and use in a layout):
<%= render partial: public_activity_view_for_key(activity.key), object: activity, as: :activity %>
In helper:
def public_activity_view_for_key(key)
"public_activity/#{key.split(".").last}"
end
Then in views/public_activity
:
_generic.html.erb # If using `display`
_create.html.erb
_destroy.html.erb
_update.html.erb
It would be better to use something like
<%= render_activity activity, display: public_activity_view_for_key(activity.key)%>
Just to have all locals there, instead of just activity
.
It will be almost perfect if we can add generic template lookup if no dedicated partial found.
@iRet that is a good idea. I will be reworking template system for activities for the 2.0 version.
Just chiming in to see how this is progressing? 😊