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