有没有机会删除RoR创建的div-container?
输入:
<%= form_for @user, :as => :user, :url => user_sign_in_path(@user) do |f| %>
<p>
输出:
<form accept-charset="UTF-8" action="/user/sign_in" class="new_user" 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="MT0OhRtfupZvi28m7bFN31JdZXyiFCGisbENml4cdcg=" /></div>
<p>
<div style="margin:0;padding:0;display:inline">
我不想要那个!
有两个隐藏文本输入是正常的吗?
<input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="MT0OhRtfupZvi28m7bFN31JdZXyiFCGisbENml4cdcg=" />
最佳答案 这是form_for的默认行为.以下是对此的官方解释:
HTML contains something extra: a div element with two hidden input
elements inside. This div is important, because the form cannot be
successfully submitted without it. The first input element with name
utf8 enforces browsers to properly respect your form’s character
encoding and is generated for all forms whether their actions are
“GET” or “POST”. The second input element with name authenticity_token
is a security feature of Rails called cross-site request forgery
protection, and form helpers generate it for every non-GET form
(provided that this security feature is enabled).
您可以在Security Guide中阅读更多相关信息.