Im trying to figure out how to use a column from another model in my Profile model
User model
has_one :profile
Profile model
belongs_to :user, :dependent => :destroy
Tried all possible options to no avail
In my profile model:
def get_column_value_from_user_model
user.username
end
What would be the right way to get a value from user model inside my profile model?
When creating a new User that calls above function to get the value from User model, from the Rails Console I get this error:
NoMethodError: undefined method `username' for nil:NilClass
the username column in User model exists.
Your Error
means there is no user object associated with that profile. Could you check what <#your_profile_object>.user_id returns?