We have a _user
partial that we want to render from two different resources, passing a collection.
The only thing that needs to change in the partial is the path inside the link_to
helper.
We can use self.send("path", object)
inside link_to
to achieve this.
<%= link_to user.name, self.send("#{path}", object, user) %>
<%= render partial: "groups/user",
collection: @event.attendees, as: :user,
locals: {
object: @event,
path: "event_attendee_path"
} %>
<%= render partial: "user",
collection: @members, as: :user,
locals: {
object: @group,
path: "group_member_path"
} %>