Rails devise registration form when having STI

南楼画角 提交于 2019-11-30 15:37:41

Ok found the answer, what you have to is add the routes for your subclasses, and then dirrect the users to the relevant routes, like such

devise_for :companies
devise_for :workers

And then you probably going to want generate the view for each of them

script/rails generate devise:views companies

If there are no major differences in your view you can just render the file from the user templates in your companies templates like so

render :file => 'users/registrations/new'

In your controllers and view you will still use the standard user_signed_in?

Hope it helps let me know if you find a better way

I think you're looking for Worker has_one User. I don't think you need to inherit your Worker class from User. If you want to create a User after creating a Worker, you can do so in a after_create callback.

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