minor refactoring for follows

This commit is contained in:
rgarcia
2017-07-19 13:52:38 +02:00
parent 57c8887077
commit b7ef755b16
3 changed files with 14 additions and 8 deletions

View File

@@ -68,8 +68,7 @@ class UsersController < ApplicationController
end end
def load_follows def load_follows
@followable_types = @user.follows.pluck(:followable_type).uniq @follows = @user.follows.group_by(&:followable_type)
@follows = @user.follows
end end
def valid_access? def valid_access?

View File

@@ -62,8 +62,16 @@ module FollowsHelper
}.invert[entity] }.invert[entity]
end end
def entity_partial(class_name) def entity_class_name(followable)
class_name.parameterize.gsub('-','_') 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 end
private private

View File

@@ -1,6 +1,6 @@
<ul class="accordion" data-accordion data-allow-all-closed="true"> <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> <li class="accordion-item" data-accordion-item>
@@ -16,9 +16,8 @@
<div class="accordion-content" data-tab-content> <div class="accordion-content" data-tab-content>
<table> <table>
<tbody> <tbody>
<% @follows.where(followable_type: followable_type).each do |follow| %> <% follows.each do |follow| %>
<%= render entity_partial(followable_type), <%= render_follow(follow) %>
entity_partial(followable_type).to_sym => follow.followable %>
<% end %> <% end %>
</tbody> </tbody>
</table> </table>