Profile model for Devise users?

前端 未结 5 1048
青春惊慌失措
青春惊慌失措 2020-11-28 02:13

I want to extend the sign up form of my devise installation. I created a Profile model and am asking myself now, how can I add specific data of the form to this model. Where

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 02:26

    It's not very clear from your question, but I'm assuming your Devise model is User and you created another model Profile that belongs to user.

    You'll need to create a controller for your User model with rails g controller users.

    You'll also need to generate the views for your users with rails generate devise:views so that the user can add profile info when he's creating his account.

    From there, it's just like any other model: create a user and profile instance and link the two. Then, in controllers, use current_user.profile to access the current user's profile.

    Note that if you're going to manage users this way, you'll need to remove the :registerable module from the User model (also read https://github.com/plataformatec/devise/wiki/How-To:-Manage-users-through-a-CRUD-interface)

提交回复
热议问题