.erb
.rb
(还不会对<input>更改)
<%= f.select :come_from,
CustomerOut::FROM,
{:prompt => CustomerOut::FROM[0][1]}, :onchange => remote_function(:update => "time_now",
:with => "'username='+$('customer_out[username]').value + '&come_from='+$('customer_out[come_from]').value",
:url =>{:action => 'check_customer'},
:before => "$('search_customer').innerHTML = '搜索中...';",
:complete => "$('search_customer').innerHTML = '';"
) %>
<div id="time_now"></div>
.rb
def check_customer
@customer_out = CustomerOut.find(:first, :conditions => ["username = ? and come_from = ?", params[:username], params[:come_from]])
if @customer_out
@consignee = @customer_out.customer.consignees.find(:first)
else
@customer_out = CustomerOut.new
@customer_out.username = params[:username].strip
@customer_out.come_from = params[:come_from]
end
render :text => Time.new.to_s
end (还不会对<input>更改)
本文介绍了一种使用Ruby on Rails实现动态表单更新的方法,并通过远程函数调用完成表单选择项改变时的时间显示更新及客户信息检查。具体展示了如何利用ERB模板语法结合Rails的表单辅助方法来达到这一目的。
621

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



