2014-10-22 24 views
1

我該怎麼做?我研究過它並找不到一個簡單的實現。如何在Rails應用程序中自動填充結算信息?

本質上,我有一個具有用戶訂閱的應用程序。在我的情況下,用戶與組織相關聯,並且需要填寫組織地址。還有「結算信息」部分,其中帶有一個複選框,其中顯示「檢查相同名稱和組織地址」。當這個複選框被點擊時,我希望從組織地址中移除並自動填寫所有地址詳細信息,即州,國家等。

請參見下面的billing_information複選框代碼:

<div class="checkbox click"> 
     <input id="check1" type="checkbox" value="check1" name="check"> 
     <label for="check1" style="color:#fff !important;" class="checkbox_label"> Check if same name and organization address</label> 
    </div> 
    <div class="form-group"> 
     <div class="row"> 
     <div class="col-md-12"> 
      <input type="text" class="form-control-input address" placeholder="Address"> 
     </div> 
     </div> 
    </div> 
    <div class="form-group"> 
     <div class="row"> 
     <div class="col-md-12"> 
      <input type="text" class="form-control-input city" placeholder="City"> 
     </div> 
     </div> 
    </div> 
    <div class="form-group"> 
     <div class="row"> 
     <div class="col-md-6 col-xs-6"> 
      <input type="text" class="form-control-input state" placeholder="State/Province/Region"> 
     </div> 
     <div class="col-md-6 col-xs-6"> 
      <input type="text" class="form-control-input zip_code" placeholder="Zip/Postal Code"> 
     </div> 
     </div> 
    </div> 
    <div class="form-group"> 
     <div class="row"> 
     <div class="col-md-6 col-xs-6" style="color:#fff; font-size:20px;"> 
      <button type="submit" class="btn btn-primary btn-lg continue-button">Update</button> 
      or <a href="#" class="cancel-t" data-dismiss='modal'>Cancel</a> 
     </div> 
     </div> 
    </div> 

許多電子商務網站有這個功能,我已經在我的設計,我只是有麻煩實施後端代碼,使其工作實施的複選框。有任何想法嗎?

謝謝!

回答

1

在點擊提交按鈕之前,您是否需要/希望信息出現在用戶的屏幕上?如果是這樣,那麼使用Javascript。 Rails無法幫助你。

如果你想要的是輸入相應的數據元素被控制器正確複製,那麼就這樣做:

order = Order.new(params) 
if params[:check1] 
    order.shipping_address = order.billing_address 
    order.shipping_city = order.billing_city 
    order.shipping_zip = order.billing_zip 
    order.shipping_state = order.billing_state 
    ... 
end 
... 
相關問題