【发布时间】:2011-07-10 21:05:33
【问题描述】:
首先,我知道我正在尝试做的不是 Rails 的典型操作。我愿意接受有关更好选择的建议。我是 Rails 新手,欢迎提出建议:)
基本上,我有一个包含 5 个通知的通知栏。在用户单击并看到通知后,我想将数据库中名为 see 的列设置为 true。
这是我的 Jquery 函数:
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("div#count").html("<%= escape_javascript(render('shared/notification_count')) %>");
});
});
</script>
这是我仅在单击后才尝试执行的代码(位于 _notification_count.html.erb 中)
<% notification_ids = current_user.notifications.map(&:id).join(', ')%>
<% sql = "UPDATE notifications SET SEEN = true where id IN(#{notification_ids})" %>
<% User.connection.select_all(sql) %>
但是,此代码似乎是在页面加载时自动执行,而不是在点击后自动执行。我的问题是什么?
【问题讨论】:
标签: jquery sql ruby-on-rails ruby postgresql