.erb
.erb
.rb
<div id="customer_out">
<%= render :partial => "customer", object => @customer_out%>
</div>.erb
<%= f.text_field :username, :onchange => remote_function(:update => "customer_out",
:with => "'username='+$(this).value + '&come_from='+$('customer_out[come_from]').value",
:url =>{:action => 'check_customer'} ) %>
.rb
def check_customer
@customer_out = CustomerOut.find(:first, :conditions => ["username = ? and come_from = ?", params[:username], params[:come_from]])
if @customer_out
@customer_out = CustomerOut.new
@consignee = @customer_out.customer.consignees.find(:first)
end
render :partial => 'customer'
end
本文展示了一个使用Ruby on Rails进行远程验证的例子。具体包括如何通过ERB模板渲染部分视图,以及利用remote_function方法实现表单字段的实时验证。
41

被折叠的 条评论
为什么被折叠?



