所以我有原始版本的设计,用户通过他们的电子邮件地址进行身份验证。但是,我想为用户添加一个选项来输入他们的名字,当然这并不重要,如果它不是唯一的,它只是用于显示目的;如何自定义设计表单?我的用户模型中有一个:name属性,这里是表单的样子:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
# This field not working
<div class="field">
<%= f.text_field :name, autofocus: true, placeholder: "What is your nickname?" %>
</div>
<div class="field">
<%= f.email_field :email, placeholder: "Enter your email address" %>
</div>
<div class="field">
<%= f.password_field :password, autocomplete: "off",
placeholder: "Enter your password" %>
</div>
<div class="field">
<%= f.password_field :password_confirmation, autocomplete: "off",
placeholder: "Confirm your password" %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
我哪里错了?当用户注册时,名称显示为空白,并且未注册到数据库中......
答案 0 :(得分:1)
我认为您的问题与Strong Params有关。将其添加到您的ApplicationController
。
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :user
end
end
来源:https://github.com/plataformatec/devise#strong-parameters