Reputation: 135
I am trying to get my user model to capitalize all names when a user signs up. It doesn't appear to the working however. I am using devise.
There is a name field in the database.
user model:
before_create :capitalize_name
def capitalize_name
name_array = name.split(" ")
name_array.each { |name| name.capitalize! }
name = name_array.join(" ")
end
Upvotes: 1
Views: 88
Reputation: 30463
The problem is that you assign the result to the local variable name
. Use self.name
.
self.name = name.split.map(&:capitalize).join(' ')
Upvotes: 3