I have this code in my user model
class User < ActiveRecord::Base
after_create :set_user_full_name
.........
private
def set_user_full_name
self.name = "Test name"
end
end
But when I create a user the name attribute is nil. I tried adding name to
create and update strong params but no luck.
devise_parameter_sanitizer.for(:sign_up) << [:name]
devise_parameter_sanitizer.for(:account_update) << [:name]
Any help would be appreciated!
after_createcallback is executed after inserting user data in db.in your code,
nameis not actually inserted.If you want to insert name attribute, use
before_createcallback.It assign name value before insert
Updated:
If User has
first_nameandlast_nameattribute,But If User does not have
first_nameandlast_nameattribute, you should handle in controller.