通知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?
在此先感謝您的任何提示/指導。如果您需要更多信息,請讓我知道,我會馬上添加。
謝謝。讓我嘗試一下。順便說一句,我有一個通知控制器,因爲我創建通知;在刪除它們之前。 –