minor refactoring for follows
This commit is contained in:
@@ -68,8 +68,7 @@ class UsersController < ApplicationController
|
||||
end
|
||||
|
||||
def load_follows
|
||||
@followable_types = @user.follows.pluck(:followable_type).uniq
|
||||
@follows = @user.follows
|
||||
@follows = @user.follows.group_by(&:followable_type)
|
||||
end
|
||||
|
||||
def valid_access?
|
||||
|
||||
@@ -62,8 +62,16 @@ module FollowsHelper
|
||||
}.invert[entity]
|
||||
end
|
||||
|
||||
def entity_partial(class_name)
|
||||
class_name.parameterize.gsub('-','_')
|
||||
def entity_class_name(followable)
|
||||
followable.class.to_s.parameterize.gsub('-','_')
|
||||
end
|
||||
|
||||
def render_follow(follow)
|
||||
followable = follow.followable
|
||||
partial = entity_class_name(followable)
|
||||
locals = {entity_class_name(followable).to_sym => followable}
|
||||
|
||||
render partial, locals
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<ul class="accordion" data-accordion data-allow-all-closed="true">
|
||||
|
||||
<% @followable_types.each do |followable_type| %>
|
||||
<% @follows.each do |followable_type, follows| %>
|
||||
|
||||
<li class="accordion-item" data-accordion-item>
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
<div class="accordion-content" data-tab-content>
|
||||
<table>
|
||||
<tbody>
|
||||
<% @follows.where(followable_type: followable_type).each do |follow| %>
|
||||
<%= render entity_partial(followable_type),
|
||||
entity_partial(followable_type).to_sym => follow.followable %>
|
||||
<% follows.each do |follow| %>
|
||||
<%= render_follow(follow) %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user