Params.require(:user).permit(:email, :password, user_profile_attributes: :username) If you have created your own RegistrationsController and extended Devise's, it should look similar to this: class RegistrationsController < Devise::RegistrationsController The user model ends up looking like so: class User Īn example of this in my specific case is: įinally, you will need to tell Devise that it should accept this new hash of arguments and pass it to the model. I will be assuming that you have some sort of setup as I do above.įirst step is you need to modify your User controller to accept_nested_attributes_for the profile reference as well as add a utility method to the model so when requested in code, the application can either retrieve the built profile model or build one. I think, instead of simply commenting on an answer that led me to the final answer, I'll archive the answer here in case someone in the future is trying to also find this answer: Is there some way to simply separate the inputs with devise and make sure the end up in the right place? These all seem too complicated for my use-case. I've also seen information about creating a wizard with WICKED, and an article on the same topic. ![]() I've seen resources about creating state machines ( AASM, and the answer to this SO question. My question, now, is, how does one collect the information for both of these models and ensure, via the devise registration form, that it all ends up in the right places? T.references :user, index: true, foreign_key: trueĪdd_index :user_profiles, Timestamp_create_user_profiles.rb class CreateUserProfiles < ActiveRecord::Migration User_profile.rb class UserProfile < ActiveRecord::Base Has_one :user_profile, dependent: :destroy User.rb (for reference) class User < ActiveRecord::Baseĭevise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable I have also created a UserProfile model via the rails generate script. ![]() Thus far, I have created a User model via Devise. But my problem is that it's saving to the User model, which, according to database normalizations ( also referencing this SO question), it should in fact be saving to a sub-model of User which is connected via has_one and belongs_to. username, biography, avatar URL, et cetera.) [resources include Jaco Pretorius' website, this (badly formed) SO question, and this SO question. Having looked at quite a few resources for adding information to the devise model (e.g. I am using Devise to build a registration/authentication system into my application.
0 Comments
Leave a Reply. |