我正在用Rails語法掙扎。我試圖爲用戶建立一對一的關係,但用戶將始終擁有主要地址。我已經設法讓模型正常工作,但我可以'似乎讓表單工作。下面的表格用於「新註冊」,但嵌套地址的字段不顯示。範圍聲明的rails語法
我一直在這個黑客攻擊,似乎無法得到它。有人能解釋爲什麼嵌套的表單字段在嘗試註冊新用戶時不會顯示出來嗎?
這是形式
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => "form-horizontal"}) do |f| %>
<small>Mandatory fields marked *</small><br><br>
<%= f.fields_for :primary_address do |address_form| %>
<div class="control-group">
<%= address_form.label :first_name, :class => "control-label" %>
<div class="controls">
<%= address_form.text_field :first_name, :class => "input-xlarge" %>
</div>
</div>
<div class="control-group">
<%= address_form.label :last_name, :class => "control-label" %>
<div class="controls">
<%= address_form.text_field :last_name, :class => "input-xlarge" %>
</div>
</div>
<% end %>
這是用戶模式:
class Member::User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :addresses_attributes
validates_presence_of :email
# each user may have zero or many addresses
# their primary email is also set as their login id.
has_many :addresses
has_one :primary_address, :class_name => "Address", :conditions => "is_primary = true"
accepts_nested_attributes_for :primary_address
end
你是不是缺少' <% end %>'在窗體的底部? –
我沒有發佈整個表格......只是相關的部分。 –