In my rails 7 app with devise set up i got the registration#new view modified to appear in my design.
My user
model also has_one :account
which stores information i dont want to be in the user
model since it's bad practice to migrate columns into the devise model. One of the things i store in the account is gdpr
which later will be displayed in the registration#new
as check box. The account
model also validates_presence_of :gdpr
.
My devise registration controller is modified, so it is able to create the user and the associated account at the same time like this:
registrations_controller.rb
# GET /resource/sign_up
def new
build_resource({})
self.resource.account = Account.new
respond_with self.resource
end
Registrations#new view
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<%= f.email_field :email, autofocus: true, placeholder: "your@mail.com", autocomplete: "email", required: true %>
.... password and password confirmation here
<%= f.fields_for :account do |account| %>
<%= account.check_box :gdpr %>
<%= account.label :gdpr do %>
I Accept all the stuff
<% end %>
<% end %>
<% end %>
The Problem:
When i sign up as new user and an error occurs (maybe because the password is too short or not matching, or the email is already taken) the fields_for
inside of my form just disappears. I followed this set up guide in the hope it would change anything but it did not. The original f.
form elements stay, but the nested form part vanishes.