如题:基于 homeland 做二次开发的时候,需要添加用户手机号字段。在 accoutn_controller 里修改如下
def create
build_resource(sign_up_params)
resource.login = params[resource_name][:login]
resource.email = params[resource_name][:email]
resource.phone_number = params[resource_name][:phone_number]
if verify_rucaptcha?(resource) && resource.save
sign_in(resource_name, resource)
end
end
视图部分修改如下:
<div class="form-group">
<%= f.text_field :phone_number, type: :text, class: "form-control input-lg", placeholder: t("activerecord.attributes.user.phone_number") %>
</div>
User model 里修改如下
ACCESSABLE_ATTRS = [:name, :email_public, :location, :company, :bio, :website, :github, :twitter,
:tagline, :avatar, :by, :current_password, :password, :password_confirmation,
:_rucaptcha, :phone_number,:phone_auth_code]
那么现在我在注册的时候,始终无法写如 phone_number 的值,打断点显示的值如下
resource
#<User id: nil, login: "flk8", name: nil, email: "[email protected]", email_md5: "a4df18915fa08b9e51e8dfa9e7787cb3", email_public: true, location: nil, location_id: nil, bio: nil, website: nil, company: nil, github: nil, twitter: nil, avatar: nil, verified: false, state: "normal", tagline: nil, created_at: nil, updated_at: nil, persistence_token: "", single_access_token: "", perishable_token: "", topics_count: 0, replies_count: 0, follower_ids: nil, team_users_count: nil, followers_count: 0, following_count: 0, phone_number: "">
sign_up_params
{"email_public"=>"1",
"password"=>"flk123",
"password_confirmation"=>"flk123",
"phone_number"=>"15627215695",
"phone_auth_code"=>"15627215695"}
params
<ActionController::Parameters {"utf8"=>"✓", "user"=>{"login"=>"flk8", "email"=>"[email protected]", "email_public"=>"1", "password"=>"flk123", "password_confirmation"=>"flk123", "phone_number"=>"15627215695", "phone_auth_code"=>"15627215695"}, "_rucaptcha"=>"wpsks", "commit"=>"注册", "controller"=>"account", "action"=>"create"} permitted: false>
求助精通 homeland 的大牛们,感激不尽!~
更新:原因是下面这个设置覆盖了 user model 的 phone_number 属性...
attr_accessor :password_confirmation, :auth_code, :phone_number