【发布时间】:2008-11-19 10:08:24
【问题描述】:
我有一个通过 AJAX 提交的表单(使用原型和内置的 rails 'form_remote_tag' 助手)。
如果存在表单验证错误,我想要更新一个 div(状态区域),但如果提交成功,则更新另一个 div(表单所在的 div)。
我的代码如下所示:
<div id="recipe-status"><!-- I want form validation errors to go here --></div>
<div id="recipe">
<%= form_remote_tag(:update => "recipe-status",
:before => "Element.show('wait-indicator')",
:success => "Element.hide('wait-indicator')",
:complete => visual_effect(:appear, "recipe-status"),
:url => { :action => 'import', :id => @recipe.id },
:failure => "alert('Unable to import recipes at present')") %>
<-- Form goes here, I want this to be replaced if the submit succeeds -->
</div>
我能想到的唯一方法是在出现验证错误时返回 HTTP 错误状态,但这似乎有点像 hack。 有没有更清洁的方法呢?
【问题讨论】:
标签: ruby-on-rails ajax prototype