Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Option For Single View Template Shared Between Trackables #124

Open
Undistraction opened this issue Oct 29, 2013 · 7 comments
Labels
Milestone

Comments

@Undistraction
Copy link

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.

@pokonski
Copy link
Member

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.

@Undistraction
Copy link
Author

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
Copy link
Author

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

@farnoy
Copy link
Contributor

farnoy commented Oct 30, 2013

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.

@iRet
Copy link

iRet commented Apr 24, 2014

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

@pokonski
Copy link
Member

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

@pokonski pokonski added this to the 2.0 milestone Aug 5, 2014
@brendon
Copy link
Contributor

brendon commented Jul 10, 2018

Just chiming in to see how this is progressing? 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants