它来自你的表格
= form_for(@user, :url => url) do |f|
= render 'shared/error_explanation', :object => @user
= f.label t('users.email')
= f.text_field :email, :autocomplete => 'off'
= f.label t('users.password')
= f.password_field :password, :autocomplete => 'off'
= f.label t('users.password_confirmation')
= f.password_field :password_confirmation, :autocomplete => 'off'
%br
= f.submit :class => 'btn'
它产生类似的东西
<form accept-charset="UTF-8" action="/users/create_by_admin" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="xxx=" /></div>
<label for="user_Email">Email</label>
<input autocomplete="off" id="user_email" name="user[email]" size="30" type="text" value="" />
<label for="user_password">password</label>
<input autocomplete="off" id="user_password" name="user[password]" size="30" type="password" />
<label for="user_password confirmation">password confirmation</label>
<input autocomplete="off" id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" />
<br>
<input class="btn" name="commit" type="submit" value="Create user" />
</form>
查看名称属性。所以params
会像{"utf8"=>"✓", "authenticity_token"=>"xxx=", "user"=>{"email"=>"qwerty@qwerty.qw", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Create user"}
并且User.creae
方法使用模型的属性获取哈希。