【发布时间】:2011-05-21 19:05:12
【问题描述】:
所以在我的应用中,我有通知和不同的记录计数,它们用于整体布局,因此在每个页面上都需要。
目前在我的 application_controller 中有很多类似的东西:
@status_al = Status.find_by_name("Alive")
@status_de = Status.find_by_name("Dead")
@status_sus = Status.find_by_name("Suspended")
@status_hid = Status.find_by_name("Hidden")
@status_arc = Status.find_by_name("Archived")
@balloon_active = Post.where(:user_id => current_user.id, :status_id => @status_al.id )
@balloon_dependent = Post.where(:user_id => current_user.id, :status_id => @status_de.id )
@balloon_upcoming = Post.where(:user_id => current_user.id, :status_id => @status_sus.id )
@balloon_deferred = Post.where(:user_id => current_user.id, :status_id => @status_hid.id )
@balloon_complete = Post.where(:user_id => current_user.id, :status_id => @status_arc.id )
.. 那真的只是一小部分,我有类似的电话至少加倍。问题是我几乎在每一页上都需要这些数字,但我觉得我在这里重复了太多次 DB wayyyy。
有更好的实现方法吗?
【问题讨论】:
-
如果他们解决了您的问题,如果您能接受我们的答案之一,那就太好了。谢谢! :)
-
很抱歉,仍在实施更改 - 答案已接受!
标签: ruby-on-rails ruby ruby-on-rails-3 controller