我有一个具有以下属性的用户模型,卖方和estado(状态)。
t.string "estado", default: "pending"
t.boolean "seller", default: false
我对用户模型进行了一些验证:
validates :seller, default: false
validates :estado, inclusion: { in: %w(Accepted),
message: "Status application: %{value}" }
由于其他情况,我正在设计(在控制器注册中,创建方法)试图更新这些字段。对于卖方来说,它起作用,对于estado来说,它没有作用
这是证明:
[4] pry(#<Users::RegistrationsController>)> resource.estado = "Accepted"
=> "Accepted"
[5] pry(#<Users::RegistrationsController>)> resource
=> #<User id: nil, email: "vendedor1@mail.com", created_at: nil, updated_at: nil, shop_id: nil, seller: true, first_name: nil, last_name: nil, birthday: nil, nationality: nil, document_type: nil, document_number: nil, expiring_date: nil, estado: "pending", admin: false>
[6] pry(#<Users::RegistrationsController>)> resource.seller = false
=> false
[7] pry(#<Users::RegistrationsController>)> resource
=> #<User id: nil, email: "vendedor1@mail.com", created_at: nil, updated_at: nil, shop_id: nil, seller: false, first_name: nil, last_name: nil, birthday: nil, nationality: nil, document_type: nil, document_number: nil, expiring_date: nil, estado: "pending", admin: false>
为什么不更新estado的值?我在控制台中看到了它,但是当我检查资源时,它仍然处于待处理状态。
我可以允许属性对此进行注释,如第一条注释所示:
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_up_params
# devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
# end
# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
# end