例如
Imagine我有以下表格
<%= form_for(@comment) do |f| %>
<%= f.hidden_field :user_id%>
<%= f.hidden_field :article_id%>
<%= f.label :content %><br />
<%= f.text_area :content %>
<%= f.submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我得到了:user_id和:article_id值:
Comment.new(:user_id => current_user.id, :article_id => @article.id)
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中显示表单时,它将如下所示:
<form action="/comments" method="post">
<input some_rails_tokens_here />
<!-- THIS AREA HERE-->
<input id="comment_user_id" name="comment[user_id]" type="hidden" value="1" />
<input id="comment_article_id" name="comment[article_id]" type="hidden" value="1" />
<!-- THIS AREA HERE-->
<label for="comment_content">Content</label><br />
<textarea id="comment_content" name="comment[content]"></textarea>
<input type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果有人更改了post参数而不是以下值:user_id => 1,它会更改为:user_id => 2.与文章相同.
我想相信这是用铁轨令牌验证的,但我不确定.