每进行几百次注册,我返回的表单数据就会损坏,我不知道为什么。
它应该看起来像:
Parameters: ... "user"=>{"first_name"=>"Bob", "last_name"=>"Smith", "email"=>"example@example.com", ...}
但出于某种原因,我们偶尔会得到如下所示的内容:
Parameters: {"ast_name"=>"Smith", "user"=>{"email"=>... # The last_name field got cut-off and wasn't included in the user params
Parameters: {"5Blast_name"=>"Smith", "user"=>{"email"=> ... # form item user[last_name] was encoded into %5Blast_name] and wasn't included in user array.
Parameters: {"ser"=> {"last_name"=>"Smith"}, "user"=>{"email"=> ... # It seems user[last_name] got truncated into ser[last_name]
我不确定为什么会发生这种情况。我们正在使用 Formtastic 来构建我们的注册表单
= simple_form_for resource, :as => resource_name, :url => registration_path(resource_name) do |f|
- if resource.errors.any?
.alert.alert-error
Please correct the following issue: #{resource.errors.full_messages.first}
= f.input :first_name, :input_html => {"data-validate" => "{required: true}"}
= f.input :last_name, :input_html => {"data-validate" => "{required: true}"}
= f.input :email, :input_html => {"data-validate" => "{required: true, email: true}"}
= f.input :password, :input_html => {"data-validate" => "{required: true, minlength: 6}"}
= f.input :delivery_zip, :label => "Zip code", :input_html => {"data-validate" => "{required: true, minlength: 5, maxlength: 5, number: true}"}
%button.btn.next{:type => "submit", :id => "sign-up-button"}
%span Next
...
:javascript
$(document).ready(function(){
$('#nav_sign_up').addClass('current');
$('form#new_user').validate();
});
它正在构建看起来非常无害的 HTML:
<form accept-charset="UTF-8" action="/users" class="simple_form new_user" id="new_user" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="[REDACTED]" /></div> <div class="control-group string required"><label class="string required control-label" for="user_first_name">First name</label><div class="controls"><input class="string required" data-validate="{required: true}" id="user_first_name" name="user[first_name]" size="50" type="text" /></div></div>
<div class="control-group string required"><label class="string required control-label" for="user_last_name">Last name</label><div class="controls"><input class="string required" data-validate="{required: true}" id="user_last_name" name="user[last_name]" size="50" type="text" /></div></div>
<div class="control-group email required"><label class="email required control-label" for="user_email">Email</label><div class="controls"><input class="string email required" data-validate="{required: true, email: true}" id="user_email" name="user[email]" size="50" type="email" value="" /></div></div>
<div class="control-group password optional"><label class="password optional control-label" for="user_password">Password</label><div class="controls"><input class="password optional" data-validate="{required: true, minlength: 6}" id="user_password" name="user[password]" size="50" type="password" /></div></div>
<div class="control-group string required"><label class="string required control-label" for="user_delivery_zip">Zip code</label><div class="controls"><input class="string required" data-validate="{required: true, minlength: 5, maxlength: 5, number: true}" id="user_delivery_zip" name="user[delivery_zip]" size="50" type="text" /></div></div>
<button class='btn next' id='sign-up-button' type='submit'>
<span>Next</span>
</button>
</form>
知道是什么导致我们的表单截断了 last_name 字段的第一个,有时是部分字段吗?