1
我想用form_for
與非主動記錄模型。Rails的form_for不填充值的字段
問題是這些字段的value
未正確初始化:即使該屬性存在,它始終爲空。
例如這個工程:
@customer = Customer.retrieve_from_api(id)
@customer.billing_address.first_name # => "Marco"
但形式不正確初始化:
<%= form_for @customer, as: :customer, url: billing_info_path, method: :put do |f| %>
...
<%= f.fields_for :billing_address do |b| %>
<div class="field">
<%# this is always blank (i.e. the initial value of the field is "") %>
<%= b.text_field :first_name %>
</div>
BTW,我知道,我可以用form_tag
,text_field_tag
並明確初始化值,但我想避免這種情況,並保持代碼幹,因爲我有很多領域
郵政.RB文件處理這個虛擬屬性 – bkunzi01
@ bkunzi01客戶對象是這樣的:https://github.com/chargebee/chargebee-ruby/blob/master /lib/chargebee/models/customer.rb – collimarco