Skip to content

Commit

Permalink
Refactor StaticPagesController
Browse files Browse the repository at this point in the history
  • Loading branch information
lujanfernaud committed Apr 7, 2018
1 parent d8f16e6 commit 73bb002
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
class StaticPagesController < ApplicationController
def home
if signed_in?
store_user_events
store_user_groups
end

store_unhidden_groups
end

private

def store_user_events
@user = User.find(current_user.id)
user_events = @user.events_from_groups
@events_count = user_events.count
@events = EventDecorator.collection(user_events.limit(6))
end

def store_user_groups
@user_groups = @user.groups
end

@groups = Group.where(hidden: false).random_selection
end
def store_unhidden_groups
@unhidden_groups = Group.where(hidden: false).random_selection
end
end
2 changes: 1 addition & 1 deletion app/views/static_pages/_unhidden_groups.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<h2 class="text-center">Unhidden Groups</h2>
<div class="row">
<%= render groups %>
<%= render unhidden_groups %>
</div>

<div class="row">
Expand Down
2 changes: 1 addition & 1 deletion app/views/static_pages/home.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
<%= render "user_groups", user_groups: @user_groups %>
<% end %>

<%= render "unhidden_groups", groups: @groups %>
<%= render "unhidden_groups", unhidden_groups: @unhidden_groups %>

0 comments on commit 73bb002

Please sign in to comment.