mau*_*ado 3 devise ruby-on-rails-3.2
您好即时通讯使用设计注册用户,我想创建每一个用户注册的时间与用户配置文件,问题是,当我尝试从剖面模型上的注册视图中添加的人的全名设计用户注册,它没有显示...
这是我的模特:
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
Run Code Online (Sandbox Code Playgroud)
这是配置文件模型
class Profile < ActiveRecord::Base
attr_accessible :email, :name, :phone, :code
belongs_to :user
validates_presence_of :user
end
Run Code Online (Sandbox Code Playgroud)
这是修改后的设计视图:
<% 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>
Run Code Online (Sandbox Code Playgroud)
我看不出为什么名称文字字段不会出现有什么问题...
谢谢您的帮助
弄清楚,这很简单我觉得不好......所以这里是:
我忘了在表单上生成一个新的配置文件,所以最终看起来像这样:
.
.
.
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= render 'shared/error_messages', object: resource %>
<div class="invisible">
<%= resource.build_profile %>
</div>
<%= 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 %>
.
.
.
Run Code Online (Sandbox Code Playgroud)
希望这也解决了别人的问题!
谢谢!
| 归档时间: |
|
| 查看次数: |
1623 次 |
| 最近记录: |