0
votes

I'm using Rails Devise. My user model has (id, first_name, last_name).

My sign up form currently includes the two fields for first_name and last_name.

I would like my signup form to have just one field, full_name

And for full_name to be a virtual attr which validates to ensure the fullname contains a first and last name (two strings)...

How can I set this up in my user model to have a full_name on user create, be validated and then set first_name and last_name.

1
I advise caution using this type of approach or "Mary Ann Summers" is gonna not be very happy about her name ending up as "Mary" "Summers" or "Mary" "Ann" depending on how you do it instead of "Mary Ann" "Summers". Almost always easier to have users enter them separately IMO as this is the least of all edge cases for some of the more unusual names. (Also, when I see 'full name' does the site want my middle name? If I have a name like Richard does it want "Richard" or is "Rick" fine, etc.). Otherwise what's not working in following the same steps you did to add 'first_name'/'last_name'?Simple Lime
(As a spoiler, once you figure out how to handle "Mary Ann Summers", the "Van Dyke" family is going to show up and none of it will work)Simple Lime

1 Answers

1
votes

You may need to configure views for registerable module

According to documentation you can generate views for a particular module and receive them all inside app/views/devise/registrations folder

rails generate devise:views -v registrations

Then just go and extend app/views/devise/registrations/new.html.erb by adding a required full-name fields