将多个电子邮件添加到用户模型
我想在使用 devise 时使用 has_many 关系向用户模型添加多个电子邮件。这是这个问题的一点扩展:How can I configure Devise for Ruby on Rails to store the emails and passwords at other place not in用户模型?
User.rb has_many :电子邮件
Email.rb 所属:用户
在我的新/编辑表单中,如何设置 xxx.email 的 fields_。我可以看到 devise 的注册页面使用“资源”。当我尝试以下代码时,它只是跳过电子邮件字段。
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= devise_error_messages!
%table{:style=>"width:400px;"}
-fields_for resource.email do |emails|
%tr
%td
= emails.label :email
%td
= emails.email_field :email
%tr
%td
= f.label :password ...
%tr
%td
= f.label :firstname ....
另外,谁来修改设备控制器中的操作?
在这种情况下,整个电子邮件块不会出现。
谢谢
I want to add multiple emails to the user model while using devise, using a has_many relationship. It's a bit of an extension to this question: How can I configure Devise for Ruby on Rails to store the emails and passwords somewhere other than in the user model?
User.rb
has_many :emails
Email.rb
belongs_to :user
In my new/edit form for devise how do I set up the fields_for xxx.email. I can see that the registration page from devise uses "resource". When I try the following code it just skips the email field.
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= devise_error_messages!
%table{:style=>"width:400px;"}
-fields_for resource.email do |emails|
%tr
%td
= emails.label :email
%td
= emails.email_field :email
%tr
%td
= f.label :password ...
%tr
%td
= f.label :firstname ....
Also, who do you modify the actions in the controller for devise?
In this case, the entire email block does not apear.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
帮助器
fields_for
需要一些数据来创建字段。对于新记录,通常需要执行诸如resource.emails.build
之类的操作来创建要显示的第一条记录。而且,我认为您应该使用
fields_for(resource.emails) 执行 |email|
。The helper
fields_for
need some data to create the fields. With new records, usually is needed you do something likeresource.emails.build
to create a first record to be showed.And also, I think you should use
fields_for(resource.emails) do |email|
.