无法更改通知系统的 rails 中布尔读取列的值
Cant change value of boolean read column in rails for notification system
我正在为我的应用程序实施通知系统。我创建了属于模型用户的 table 通知(一个用户有很多通知)。 Table 通知有列 content(string) 和 read(boolean)
我有一个导航栏,其中有一个显示未读通知的下拉菜单和一个脚本,该脚本假设通过单击 ajax post 将通知的已读列从 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 导致我的 notifications_controller 的操作看起来像这样:
def update_notif
current_user.notifications.each do |notification|
notification.read == true
notification.save
end
render nothing: true
end
但在那之后,当我检查 rails 控制台时,读取的布尔值没有任何改变。
我做错了什么?
请将这样的方法 notification.read == true
更新为 notification.read = true
。
def update_notif
current_user.notifications.each do |notification|
notification.read = true
notification.save
end
render nothing: true
end
我正在为我的应用程序实施通知系统。我创建了属于模型用户的 table 通知(一个用户有很多通知)。 Table 通知有列 content(string) 和 read(boolean) 我有一个导航栏,其中有一个显示未读通知的下拉菜单和一个脚本,该脚本假设通过单击 ajax post 将通知的已读列从 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 导致我的 notifications_controller 的操作看起来像这样:
def update_notif
current_user.notifications.each do |notification|
notification.read == true
notification.save
end
render nothing: true
end
但在那之后,当我检查 rails 控制台时,读取的布尔值没有任何改变。
我做错了什么?
请将这样的方法 notification.read == true
更新为 notification.read = true
。
def update_notif
current_user.notifications.each do |notification|
notification.read = true
notification.save
end
render nothing: true
end