我正在关注 railcast 嵌套形式
例如:我在注册页面上有 4 个字段,在编辑页面上有 12 个字段(实际上,我需要更多基本信息)
当新客户注册时,他们会在编辑页面上填写所有 12 个字段,并且所有内容都运行良好。
但是,当老客户登录时(在嵌套表单创建之前已经注册)他们现在没有得到所有字段,只得到 4 个字段
我正在使用这样的东西:
控制器
def new
@user = User.new
@user.build_user_nickname_live
@user.build_user_twitter_chipcount
@user.user_twitter_reals.build
@user.user_twitter_fakes.build
end
def edit
@user = User.find(current_user.id)
end
模型
has_one :user_nickname_live
accepts_nested_attributes_for :user_nickname_live
has_one :user_twitter_chipcount
accepts_nested_attributes_for :user_twitter_chipcount
has_many :user_twitter_reals, :dependent => :destroy
accepts_nested_attributes_for :user_twitter_reals,
:allow_destroy => true
has_many :user_twitter_fakes, :dependent => :destroy
accepts_nested_attributes_for :user_twitter_fakes,
:allow_destroy => true
看法
<%= nested_form_for(resource, :as => resource_name,
:url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<div style="overflow: hidden;display: block;">
<%= f.fields_for :user_nickname_live do |user_nickname_live| %>
<!--span 2 and 4 with min-padding-->
<div class="span2 min-padding">
<label >Live Nickname</label>
</div>
<div class="span4 min-padding">
<div class="input-control text">
<%= user_nickname_live.text_field :nickname,:style=>"max-width: 253px;", :placeholder=>"Live nickname",:onchange=>"changeInfo();" %>
</div>
</div>
<!--ends-->
<% end %>
</div>
<div style="overflow: hidden;display: block">
<%= f.fields_for :user_twitter_chipcount do |user_twitter_chipcount| %>
<!--span 2 and 4 with min-padding-->
<div class="span2 min-padding">
<label >Chip count account</label>
</div>
<div class="span4 min-padding">
<div class="input-control text">
<%= user_twitter_chipcount.text_field :twitter_url,:style=>" max-width: 250px;", :id=>"twitter_url", :placeholder=>"Chip count account" ,:onchange=>"changeInfo();" %>
</div>
</div>
<!--ends-->
<% end %>
</div>
<div id="real-one" style="display:block;position: relative;">
<div class="add-click">
<%= f.link_to_add "", :user_twitter_reals, :class=>"icon-plus",:style=>"font-size: 14px;", :data => { :target => "#real-field" } %>
</div>
<%= f.fields_for :user_twitter_reals do |real_one| %>
<div id="real-field" style="overflow: hidden;">
<!--span 2 and 4 with min-padding-->
<div class="span2 min-padding">
<label >Real</label>
</div>
<div class="span4 min-padding">
<div class="input-control text" >
<%= real_one.text_field :twitter_url,:style=>"max-width: 250px;",:placeholder=>"Real",:onchange=>"changeInfo();" %>
<%= real_one.link_to_remove "", :class=>"icon-minus minus-click" %>
</div>
</div>
<!--ends-->
</div>
<% end %>
</div>
<div id="twitter-fake" style="display: block;position: relative;">
<div class="add-click">
<%= f.link_to_add "", :user_twitter_fakes, :class=>"icon-plus",:style=>"font-size: 14px;", :data => { :target => "#fake-field" } %>
</div>
<%= f.fields_for :user_twitter_fakes do |user_twitter_fake| %>
<div id="fake-field" style="overflow: hidden;">
<!--span 2 and 4 with min-padding-->
<div class="span2 min-padding">
<label >Fake</label>
</div>
<div class="span4 min-padding">
<div class="input-control text">
<%= user_twitter_fake.text_field :twitter_url,:style=>"max-width: 250px;",:placeholder=>"Fake",:onchange=>"changeInfo();" %>
<%= user_twitter_fake.link_to_remove "", :class=>"icon-minus minus-click" %>
</div>
</div>
<!--ends-->
</div>
<% end %>
</div>
<% end %>
请帮帮我。