【发布时间】:2013-08-19 15:17:37
【问题描述】:
我有这个红宝石代码:
link_to t("general.actions.#{ action }"), [action, @app, item], {
:method => :put,
:remote => true,
:onclick => '$(this).closest("tr").find("td").fadeOut()'
}, :class => 'status'
生成这个 html:
<a href="/apps/guess-the-model/contents/52118140d644363dc4000005/approve"
data-method="put"
data-remote="true"
onclick="$(this).closest("tr").find("td").fadeOut()"
rel="nofollow">
approve
</a>
问题是,我不应该使用 onclick。只有当 AJAX 成功时我才应该调用这个 js 代码,所以我应该以某种方式传递一个回调并检查 XMLHttpRequest 状态。如何使用:remote => true 和:method= :put 做到这一点?
【问题讨论】:
-
我觉得,你应该把这个js写在方法的js模板中,这个模板是被远程链接调用的。
标签: ruby-on-rails ajax callback link-to link-to-remote