Skip to content

Commit

Permalink
close #86 ユーザすべてを取得する処理をリファクタリング
Browse files Browse the repository at this point in the history
  • Loading branch information
8398a7 committed Jun 21, 2015
1 parent 207d466 commit 9f861b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,9 +18,15 @@ def call_back
json[user.id] = {
title: score.title,
stateColor: color[score.state],
updatedAt: "<a href=\"#{show_log_path(user.iidxid, score.updated_at.to_date.strftime)}\">#{score.updated_at}</a>"
updatedAt: "<a href=\"#{show_log_path(user.iidxid, score.updated_at)}\">#{score.updated_at}</a>"
}
end
render json: json
end

private

def load_users
@users = User.all
end
end
2 changes: 1 addition & 1 deletion app/decorators/score_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9f861b0

Please sign in to comment.