2013-07-25 4 views
0

대시 보드 뷰의 컨트롤러 메서드에 표시되는 정보의 양이 걱정됩니다. 기본적으로이 대시 보드 뷰는 내 응용 프로그램 내부의 사용자 정보와 활동을 보여 주지만, 정보에 대한 양이 많아지면 빠르게 뒤죽박죽이되어 버리는 것 같습니다.컨트롤러 메서드에 대한 정보량 - 레일

@answered = answered.length 
@asked = asked.length 
@pending = pending.length 
@favorited = favorited.length 
@medal_gold = thanks_received(:awesome).length 
@medal_silver = thanks_received(:great).length 
@medal_bronze = thanks_received(:good).length 
@notification_pending = question_users_not_seen(pending, current_user.user_notification.pending_last_seen).count 
@notification_silver = question_users_not_seen(thanks_received(:great), current_user.user_notification.silver_last_seen).count 
@notification_gold = question_users_not_seen(thanks_received(:awesome), current_user.user_notification.gold_last_seen).count 
@notification_bronze = question_users_not_seen(thanks_received(:good), current_user.user_notification.bronze_last_seen).count 
@notification_asked = question_users_not_seen(asked, current_user.user_notification.asked_last_seen).any? 
@notification_answered = question_users_not_seen(answered, current_user.user_notification.answered_last_seen).any? 
@notification_favorited = question_users_not_seen(favorited, current_user.user_notification.favorited_last_seen).any? 

이 모든 정보를보다 우아하게 작성하는 방법이 있습니까? 나는 코드가 어떻게 보이는지에 대해서만 걱정한다.

+0

당신은이 값에 관련된 모델에 대한 자세한 헬퍼, 또는 클래스 메소드를 사용 할 수 있습니다 .. –

답변

1

해시를 사용하는 것이 좋습니다. 예를 들어,

@attr_counts = {:answered => answered.length, :asked => asked.length, :pending => pending.length, :favorited => favorited.length} 
@medal_lengths = {:gold => thanks_received(:awesome).length, :silver => thanks_received(:great).length, :bronze => thanks_received(:good).length} 
관련 문제