2
我有问题添加一个嵌套模型到窗体。具体而言,此表单部分中没有任何内容。如何使用Rails 5中的fields_for渲染此表单?
new.html.erb
<%= render 'form' %>
_form.html.erb
...
<% fields_for :bigip do |f| %>
<%= f.text_field :bgname %>
<%= f.text_field :bguser %>
<%= f.text_field :bgpassword %>
<% end %>
...
下面是基本模型和控制器。
pool.rb
class Pool < ApplicationRecord
has_one :bigip, inverse_of: :pool
accepts_nested_attributes_for :bigip, :allow_destroy => true
end
bigip.rb
class Bigip < ApplicationRecord
belongs_to :pool
end
pools_controller.rb
def new
@pool = Pool.new
@pool.build_bigip
end
'<%= f.fields_for:big_ip do | big_ip_form |%> ...'请注意”=“和”f。“。 –