您好我使用设计来注册用户,并且我想在每次用户注册时创建与用户相关的个人资料,问题是当我尝试在注册视图中添加个人资料模型中的人的全名时设计的用户注册,它没有显示...
这是我的模型:
class 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, :profile_attributes
has_one :profile, dependent: :destroy
accepts_nested_attributes_for :profile
# attr_accessible :title, :body
end
这是配置文件模型
class Profile < ActiveRecord::Base
attr_accessible :email, :name, :phone, :code
belongs_to :user
validates_presence_of :user
end
这是修改后的设计视图:
<% provide(:title, 'Sign up' ) %>
<h2>Sign up</h2>
<div class="row">
<div class="span6 offset3">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= render 'shared/error_messages', object: resource %>
<%= f.fields_for :profile do |profile_form| %>
<%= profile_form.label :full_name %>
<%= profile_form.text_field :name %>
<% end %>
<%= f.label :email %>
<%= f.email_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
<div class="form-actions">
<%= f.submit "Sign up", class: "btn btn-large btn-primary" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
</div>
</div>
我看不出为什么名称文本字段不会出现有任何问题...
感谢您的帮助