I ran into small problem here, but couldn't find the solution
anywhere.
I have this model:
create_table :users do |t|
t.column "username", :string
t.column "email", :string
t.column "password", :string
end
I want to force User.username to be in lowercase in every save/update.
So, if I fill 'MeMbeR', no error raised, but it's saved as 'member' in
the table. I tried this way:
def username
@username
end
def username=(user)
@username = user.downcase
end
But it results in username being NULL in the table.
I ran into small problem here, but couldn't find the solution
anywhere.
I have this model:
create_table :users do |t|
t.column "username", :string
t.column "email", :string
t.column "password", :string
end
I want to force User.username to be in lowercase in every save/update.
So, if I fill 'MeMbeR', no error raised, but it's saved as 'member' in
the table. I tried this way:
def username
@username
end
def username=(user)
@username = user.downcase
end
But it results in username being NULL in the table.
Any advice would be very helpful. Thanks.
AR model attributes aren't simply instance variables. The api docs for
ActiveRecord::Base explain how you go about overriding the default
accessors.
I ran into small problem here, but couldn't find the solution
anywhere.
I have this model:
create_table :users do |t|
t.column "username", :string
t.column "email", :string
t.column "password", :string
end
I want to force User.username to be in lowercase in every save/update.
So, if I fill 'MeMbeR', no error raised, but it's saved as 'member' in
the table. I tried this way:
def username
@username
end
def username=(user)
@username = user.downcase
end
But it results in username being NULL in the table.