【发布时间】:2023-03-13 23:47:02
【问题描述】:
应用程序具有为每个用户记录并记录在数据库表notifications 中的某些操作。该表的结构如下:
user_id, notification_type, credit, timestamp
notification_type 不存储通知的整个文本,而仅存储简短的类型描述。
稍后当用户想要查看他的通知时,我会使用视图中的辅助方法来获取实际文本。
def notification_text(type)
case type_id
when 'flagPositive'
return 'A question you flagged has been marked as correct.'
when 'qAccepted'
return 'A question you added has been accepted.'
when 'qModerated'
return 'You moderated a question.'
when 'flagReport'
return 'You moderated a flag.'
end
end
1) 这是执行此操作的最佳方式吗?
2) 是否应该将 type_description 替换为整数值(例如 1 -> flagPositive、2-> qAccepted)以获得性能优势?
3) 是否有任何我应该遵循的最佳实践?
【问题讨论】:
标签: ruby-on-rails notifications