如何向设计“注册"页面添加其他字段? [英] How do I add additional fields to the Devise 'sign up' page?

查看:21
本文介绍了如何向设计“注册"页面添加其他字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Rails 很陌生,所以我开始设计......

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

我已经安装了 devise 并且一切正常,但我想在我的注册页面中添加更多字段.例如,我有一个我想添加的用户类型下拉列表(由用户类型模型填充 - 在测试中工作正常),并且还想根据用户类型收集不同的信息(CC 信息等).) 有人可以指出我的资源或其他东西.我尝试覆盖 Registration 控制器,但这并没有链接回设计视图或符合我的 DRY 原则(复制视图).提前感谢您的建议.

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.

推荐答案

只需向用户添加列,然后在视图中添加其他功能即可.

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

script/generate migration add_user_type_to_user

然后在您的迁移 rake 文件中:

Then in your migration rake file:

add_column :users, :user_type, :string

然后rake db:migrate.接下来你可以在你的视图中添加一个下拉菜单,你可以通过 rails generate devise:views:

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'])%>

这篇关于如何向设计“注册"页面添加其他字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆