From 51fcbd9176820a53544241c034b879fe3745f1ef Mon Sep 17 00:00:00 2001 From: Mauricio Giacomini Girardello <mauriciogiacomini4@gmail.com> Date: Wed, 14 Oct 2015 13:45:42 -0300 Subject: [PATCH] refactoring users controller --- app/controllers/users_controller.rb | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 17b22df42..ecc8069a7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,45 +2,40 @@ class UsersController < ApplicationController before_action :authenticate_user!, only: :me before_action :check_current_user_page, only: :show before_action :set_user, only: :show + before_action :set_empty_collection, only: [:show, :me] def show - @objects = learning_object_repository.all_from_offset_to_limit 0, 10 - @new_collection = Collection.new - + @objects = @user.learning_objects @groups = [ CollectionsGroup.new(title: 'Coleções Automáticas', collections: [ @new_collection ]), - CollectionsGroup.new(title: 'Coleções adicionadas', + CollectionsGroup.new(title: 'Coleções Adicionadas', collections: [ - @new_collection + @user.collections ]) ] end def me - @objects = learning_object_repository.all_from_offset_to_limit 0, 10 - @new_collection = Collection.new - @bookmarks = Collection.new(name: 'Favoritos') - @add1 = Collection.new(name: 'Aula fÃsica quantica - turma b') - @add2 = Collection.new(name: 'Aula segunda lei de newton - turma a') - + @objects = current_user.learning_objects + @bookmarks = current_user.bookmarks @groups = [ CollectionsGroup.new(title: 'Coleções Automáticas', - collections: [ - @bookmarks - ]), + collections: [@bookmarks]), CollectionsGroup.new(title: 'Coleções Adicionadas', - collections: [ - @add1, @add2 - ]) + collections: current_user.collections) ] end private + def set_empty_collection + @new_collection = Collection.new + end + def set_user @user = user_repository.find params[:id] end -- GitLab