How do I add additional fields to the Devise 'sign up' page?

我的梦境 提交于 2020-01-10 23:15:19

问题


I'm very new to Rails and devise so here goes...

I've installed devise and everything is working fine but I'd like to add a few more fields to my registration page. For instance, I have a usertype drop down that I'd like to add (populated by a Usertype Model - works fine in test) and would also like to collect different information depending on the type of user it is (CC information, etc.) Can someone point me to a resource or something. I tried overriding the Registration controller but that didn't link back to the devise views or fall in line with DRY principles to me (to copy the views). Thanks in advance for suggestions.


回答1:


Just add columns to the user and then add additional features in the views.

script/generate migration add_user_type_to_user

Then in your migration rake file:

add_column :users, :user_type, :string

and then rake db:migrate. Next you can add a drop down to your view and you can get those through rails generate devise:views:

<%= f.select :user, :user_type options_for_select(['admin', 'no status'])%>



回答2:


It worked very fine, but I had to add the attr_acessors to my Users Model.

Just in the case of someone looking why it doesn´t persist the new collumn




回答3:


rails generate devise:views will copy all views to your application. That's the intended way to customize devise templates (Source).



来源:https://stackoverflow.com/questions/5241486/how-do-i-add-additional-fields-to-the-devise-sign-up-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!