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
The helper
fields_forneed some data to create the fields. With new records, usually is needed you do something likeresource.emails.buildto create a first record to be showed.And also, I think you should use
fields_for(resource.emails) do |email|.