我试图在我的设计表单上添加一个额外字段,如下所示:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="user_field">
<div class="email">
<%= f.label :email %><br />
</div>
<%= f.email_field :email, autofocus: true, autocomplete: "email"%>
</div>
<div class="pass_field">
<div class="password_field">
<%= f.label :password %>
<% if @minimum_password_length %>
<em class = "minimum">(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
</div>
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<div class="confirmation_field" input type = "hidden">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
</div>
<input type="hidden" id="public_key" name="public_key" value="" />
<script type="text/javascript">
document.getElementById("public_key").value = getkey();
</script>
我必须允许额外的字段,所以我创建了一个新的初始值设定项designe\u allowed\u参数。rb像这样
module DevisePermittedParameters
extend ActiveSupport::Concern
included do
before_filter :configure_permitted_parameters
end
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :password, :password_confirmation])
end
end
DeviseController.send :include, DevisePermittedParameters
输出如下:
Parameters: {"utf8"=>"â", "authenticity_token"=>"8kB8VeA7pvoK0ROvfwwvibyyBUY/FOEHHYDYJbaBVz7+D2O3HrTYQihU1u8ePYC7nxH8qI2bJpWBjX2NZE0XIA==", "user"=>{"email"=>"wtgwg@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "public_key"=>"qEqGEPmShqM27Gc9CtYPfliPCRI7TQG3xTLZtl3ccIqQJwrvWS6jjZxkiJoM8fD/F4fL2y5xLH5S0Ye5LUiQJQ3SXqrGq1wbRwzEX1Y3GvV1dnNfwBcWvDkigQPvX11MUbzjf3Xiqf+1AtIaWY2+AB04Xou79BEgOtSSc8GDob0=", "commit"=>"Sign up"}
(0.2ms)开始事务
用户存在(0.3ms)从“用户”中选择1,其中“用户”。“电子邮件”=?限度[[“电子邮件”,”wtgwg@gmail.com“],[“限制”,1]]
SQL(1.1ms)插入“用户”(“电子邮件”、“加密密码”、“创建时间”、“更新时间”)值(?,,?,?)[[“email”,“hey”],[“encrypted\u password”,“$2a$11$ew.ubHvxuvMrTHsuUqA8xu7ND7Xj3oGtNNR9YkziamJwPldsqvx22”],[“created\u at”,“2018-04-10 17:07.819645”],[“updated\u at”,“2018-04-10 17:17:07.819645”]
问题是存储了public\u密钥。有什么帮助吗?