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

User page: new following section #1750

Merged
merged 17 commits into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def load_budget_investments
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?
Expand Down
12 changes: 10 additions & 2 deletions app/helpers/follows_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ def entity_icon(entity)
}.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
Expand Down
7 changes: 3 additions & 4 deletions app/views/users/_following.html.erb
Original file line number Diff line number Diff line change
@@ -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>

Expand All @@ -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) %>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@voodoorai2000 nice refactor! 😍

<% end %>
</tbody>
</table>
Expand Down