论坛首页 编程语言技术论坛

remote_function without erb

浏览 2013 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-03-31  
.erb
  <%= 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>更改)
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics