public_activity icon indicating copy to clipboard operation
public_activity copied to clipboard

Feature Request: Option For Single View Template Shared Between Trackables

Open Undistraction opened this issue 11 years ago • 7 comments

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.

Undistraction avatar Oct 29 '13 18:10 Undistraction

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.

pokonski avatar Oct 30 '13 11:10 pokonski

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.

Undistraction avatar Oct 30 '13 11:10 Undistraction

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

Undistraction avatar Oct 30 '13 12:10 Undistraction

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.

farnoy avatar Oct 30 '13 14:10 farnoy

It will be almost perfect if we can add generic template lookup if no dedicated partial found.

iRet avatar Apr 24 '14 10:04 iRet

@iRet that is a good idea. I will be reworking template system for activities for the 2.0 version.

pokonski avatar Apr 24 '14 11:04 pokonski

Just chiming in to see how this is progressing? 😊

brendon avatar Jul 10 '18 00:07 brendon