I'm using Rails Devise. My user model has (id, first_name, last_name).
我正在使用Rails Devise。我的用户模型有(id,first_name,last_name)。
My sign up form currently includes the two fields for first_name and last_name.
我的注册表单目前包含first_name和last_name的两个字段。
I would like my signup form to have just one field, full_name
我希望我的注册表单只有一个字段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)...
并且for full_name是一个虚拟attr,它验证以确保fullname包含名字和姓氏(两个字符串)......
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.
如何在我的用户模型中进行设置,以便在用户创建时使用full_name,进行验证,然后设置first_name和last_name。
Thanks
谢谢
1 个解决方案
#1
1
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
根据文档,您可以为特定模块生成视图,并在app / views / devise / registrations文件夹中接收它们
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
然后通过添加必需的全名字段来扩展app / views / devise / registrations / new.html.erb
#1
1
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
根据文档,您可以为特定模块生成视图,并在app / views / devise / registrations文件夹中接收它们
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
然后通过添加必需的全名字段来扩展app / views / devise / registrations / new.html.erb