My application has Users
and Dwellings
. When a user
creates a dwelling
, the user
becomes the owner
The exact problem really depends on details of your application we haven't seen yet. For example, we don't know what current_user
is defined as, we don't know how your users are created, we don't know any details about your forms, etc.
I don't have much more time to work on this right now, but you might try the following things.
First, remove has_secure_password
from your User
model and see if you still experience the issue. This is just for troubleshooting, as eventually you'll want to add has_secure_password
back in.
Make sure your users table has a password_digest
column.
Make sure the current_user
has a value in the users table for password_digest
Perhaps you created the user before you added the has_secure_password
feature, which would result in a NULL value for password_digest
.
Make sure that current_user
is actually a persisted (i.e. in the database) user. You can do this by adding the following line above current_user.save!
:
raise StandardError, "current_user is not persisted" unless current_user.persisted?
I'm assuming current_user
already exists as a persisted user. If you're actually doing something fancier like trying to create the user and the dwelling in the same form, then there are several other factors that need to be considered.
I won't have additional time to help with this for a while. Best wishes getting it solved.