DEVISE额外字段未保存到数据库

时间:2018-04-10 17:49:27

标签: ruby-on-rails devise

我正在尝试在我的设计表单上添加一个额外的字段:

<%= 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>

我必须允许额外的字段,所以我创建一个新的初始化程序devise_permitted_pa​​rameters.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作为一个FROM&#34;用户&#34;在哪里&#34;用户&#34;。&#34;电子邮件&#34; =?限制? [[&#34; email&#34;,&#34; wtgwg@gmail.com"],[&#34; LIMIT&#34;,1]]   SQL(1.1ms)INSERT INTO&#34;用户&#34; (&#34;电子邮件&#34;,&#34; encrypted_pa​​ssword&#34;,&#34; created_at&#34;,&#34; updated_at&#34;)VALUES(?,?,?,?)[[& #34;电子邮件&#34;,&#34;嘿&#34;],[&#34; encrypted_pa​​ssword&#34;,&#34; $ 2a $ 11 $ ew.ubHvxuvMrTHsuUqA8xu7ND7Xj3oGtNNR9YkziamJwPldsqvx22&#34;],[&#34; created_at& #34;,&#34; 2018-04-10 17:17:07.819645&#34;],[&#34; updated_at&#34;,&#34; 2018-04-10 17:17:07.819645&# 34;]]

问题是public_key正在存储。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

以表格

试试
<%= f.text_field :public_key,id: "public_key" ,class: "hidden", value: "" %>

而不是

<input type="hidden" id="public_key" name="public_key" value="" />