I have a User model:
create_table "users", force: true do |t|
t.string "name"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "password_digest"
end
add_index "users", ["name"], name: "index_users_on_name"
Then, I have the following validation:
class User < ActiveRecord::Base
has_secure_password
validates :password, length: {minimum: 4}
end
Then, I update in my controller the name and email of a certain user:
...
logger.debug('++++++++ new_values after: '+new_values.inspect)
if @user.update_attributes(new_values)
logger.debug('+++++++++++++ SUCCESS')
...
end
(new_values is of type ActionController::Parameters)
My log shows
++++++++ new_values after: {"name"=>"1111", "email"=>"1111"}
However, the update_attributes fails, and the error message says:
Password is too short (minimum is 4 characters)
What I don't understand is, that I don't supply a new password. Why,
then, is password validation triggered here? And how should I implement
this?
Background for this question:
This code is executed only, when a user wants to edit his profile data
(which, for the time being, consist only of name and email). It is
ensured that only a logged in user can execute this code, and only for
his own data. Therefore, I don't require to enter the password. He had
entered it anyway when logging in.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fd05f515f4de339941398f1edba11c56%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment