ruby - Attempting to create a database item using the has_one relationship, no exceptions, but still no item -
models: user has_one ucellar ucellar belongs_to user have confirmed multiple sources these set correctly. posterity, here top portion of 2 models.
class user < activerecord::base has_many :authorizations has_one :ucellar validates :name, :email, :presence => true
this entire ucellar model.
class ucellar < activerecord::base belongs_to :user end
ucellar has column called user_id, know necessary. part of application creates user uses method create_with_oath. below entire user class. note second line of create method.
class user < activerecord::base has_many :authorizations has_one :ucellar validates :name, :email, :presence => true def create @user = user.new(user_params) @ucellar = @user.create_ucellar end def add_provider(auth_hash) # check if provider exists, don't add twice unless authorizations.find_by_provider_and_uid(auth_hash["provider"], auth_hash["uid"]) authorization.create :user => self, :provider => auth_hash["provider"], :uid => auth_hash["uid"] end end def self.create_with_omniauth(auth) user = user.create({:name => auth["info"]["name"], :email => auth["info"]["email"]}) end private def user_params params.require(:user).permit(:name, :email) end end
edit: forgot summarize symptoms. on create, user in db, no exceptions thrown, , nothing signify went wrong. however, related ucellar never created. per documentation here, create method should create , save related ucellar.
it should create ucellar too. try error messages after creation calling:
raise @user.errors.full_messages.to_sentence.inspect
Comments
Post a Comment