.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>更改)