From 9f861b0dacf735cc2e6b551b628204357b21025f Mon Sep 17 00:00:00 2001 From: 839 <8398a7@gmail.com> Date: Sun, 21 Jun 2015 14:05:37 +0900 Subject: [PATCH] =?UTF-8?q?close=20#86=20=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=81=99=E3=81=B9=E3=81=A6=E3=82=92=E5=8F=96=E5=BE=97=E3=81=99?= =?UTF-8?q?=E3=82=8B=E5=87=A6=E7=90=86=E3=82=92=E3=83=AA=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 16 +++++++++++----- app/decorators/score_decorator.rb | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f895d1dd..aecfd2ca 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,15 +1,15 @@ class UsersController < ApplicationController + before_action :load_users + def index @cnt = User.select(:id).count - @users = User.all end def call_back json = {} color = Static::COLOR - users = User.where(id: JSON.parse(params[:id])) - users.each do |user| - score = user.scores.order(updated_at: :desc).find_by(state: 0..6) + @users.each do |user| + score = user.scores.last_updated unless score json[user.id] = { title: '', stateColor: '', updatedAt: '' } next @@ -18,9 +18,15 @@ def call_back json[user.id] = { title: score.title, stateColor: color[score.state], - updatedAt: "#{score.updated_at}" + updatedAt: "#{score.updated_at}" } end render json: json end + + private + + def load_users + @users = User.all + end end diff --git a/app/decorators/score_decorator.rb b/app/decorators/score_decorator.rb index cd3bf914..e356e8d8 100644 --- a/app/decorators/score_decorator.rb +++ b/app/decorators/score_decorator.rb @@ -2,7 +2,7 @@ class ScoreDecorator < Draper::Decorator delegate_all def updated_at - return '不明' unless object.updated_at + return '' unless object.updated_at object.updated_at.to_date.strftime end end