【发布时间】:2015-05-22 05:53:29
【问题描述】:
我正在为我的应用实施通知系统。我创建了一个属于模型 User 的表通知(一个用户有很多通知)。表通知有列内容(字符串)和读取(布尔) 我有一个带有下拉菜单的导航栏,显示未读通知和一个脚本,该脚本假设通过点击时的 ajax 帖子将通知的已读列从 false 更改为 true。
<script>
$(document).ready(function() {
$("#dropdownMenu1").on('click', function(event){
$.ajax({url: "<%=update_notification_path%>",
dataType: "json",
type: "POST",
success: function() {
$(".noti_bubble").hide();
},
});
});
});
这个 ajax 导致我的通知控制器的操作如下所示:
def update_notif
current_user.notifications.each do |notification|
notification.read == true
notification.save
end
render nothing: true
end
但在那之后,当我检查 rails 控制台时,读取的布尔值没有任何改变。
我做错了什么?
【问题讨论】:
-
您能描述一下
update_notification_path的定义位置吗? -
在配置/路由
post "updatenotif", to: "notifications#update", as: "update_notification"
标签: ruby-on-rails ajax notifications