通知belongs_to用户和用户have_many通知。清除用户通知
用户的显示(users_controller.rb)动作我通过检索用户的通知:
def show
...
@notifications = current_user.notifications if current_user
end
通知是正常显示,但后来我想用户能够删除他/她的通知。我把这个在UsersHelper.rb:
def clearNotifications(notifs)
destroynotifs = notifs.destroy
end
我的观点(用户/ show.html.erb),这没有任何意义是:
<div id="clearnotifications">
<% clearNotifications(@notifications) %>
clear notifications
</div>
有三个问题,我关注:
- 这是一个很好的做法吗?
- 如何从视图上的文本调用此函数? (link_to?)
- 我不应该打电话给users.save或notifications.save?
在此先感谢您的任何提示/指导。如果您需要更多信息,请让我知道,我会马上添加。
谢谢。让我尝试一下。顺便说一句,我有一个通知控制器,因为我创建通知;在删除它们之前。 –