我想扩展我的devise安装的注册表单。我创建了一个配置文件模型,现在我问自己,如何才能将表单的特定数据添加到此模型中。devise的UserController在哪里?
提前感谢!
发布于 2010-12-01 03:16:12
假设您有一个具有has_one配置文件关联的用户模型,您只需要在User中允许嵌套属性并修改您的devise注册视图。
运行rails generate devise:views命令,然后使用fields_for表单助手修改devise registrations#new.html.erb视图,如下所示,让您的注册表单随用户模型一起更新您的配置文件模型。
<div class="register">
<h1>Sign up</h1>
<% resource.build_profile %>
<%= form_for(resource, :as => resource_name,
:url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<h2><%= f.label :email %></h2>
<p><%= f.text_field :email %></p>
<h2><%= f.label :password %></h2>
<p><%= f.password_field :password %></p>
<h2><%= f.label :password_confirmation %></h2>
<p><%= f.password_field :password_confirmation %></p>
<%= f.fields_for :profile do |profile_form| %>
<h2><%= profile_form.label :first_name %></h2>
<p><%= profile_form.text_field :first_name %></p>
<h2><%= profile_form.label :last_name %></h2>
<p><%= profile_form.text_field :last_name %></p>
<% end %>
<p><%= f.submit "Sign up" %></p>
<br/>
<%= render :partial => "devise/shared/links" %>
<% end %>
</div>在你的用户模型中:
class User < ActiveRecord::Base
...
attr_accessible :email, :password, :password_confirmation, :remember_me, :profile_attributes
has_one :profile
accepts_nested_attributes_for :profile
...
endhttps://stackoverflow.com/questions/4307743
复制相似问题