Ruby on rails RubyonRails:设计gem,添加一个;名称“;到用户模型
因此,我有Desive的原始版本,其中用户通过其电子邮件地址进行身份验证。然而,我想为用户添加一个选项来输入他们的名字,如果不是唯一的,当然这并不重要,它只是为了显示的目的;如何定制Desive表单?我的用户模型中已经有一个:name属性,下面是表单的外观:Ruby on rails RubyonRails:设计gem,添加一个;名称“;到用户模型,ruby-on-rails,ruby,devise,Ruby On Rails,Ruby,Devise,因此,我有Desive的原始版本,其中用户通过其电子邮件地址进行身份验证。然而,我想为用户添加一个选项来输入他们的名字,如果不是唯一的,当然这并不重要,它只是为了显示的目的;如何定制Desive表单?我的用户模型中已经有一个:name属性,下面是表单的外观: <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> # This field
<%= 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 %>
#这个领域不起作用
我哪里做错了?当用户注册时,名称显示为空,并且未注册到数据库中…我认为您的问题与。将其添加到您的
应用程序控制器
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
class ApplicationController 设计参数消毒剂。对于(:注册)在多次无用的教程之后,我没有想到去看官方文档,非常感谢:)