从视图中删除 rails 个真实性令牌

Remove rails authenticity token from view

我在@bar 的控制器中预先填充了表单字段,当表单在视图中呈现时,它还会在视图中显示 authenticity_token

def new
  @content = params[:foo][:id]
  @foo = Foo.find(@content)
  @bar = Bar.new(title: @foo.title, body: @foo.body, foo_id: @foo.id)
end

截图

查看代码:

      <%= form_for @bar do |f| %>
          <p>
            <strong>Title: </strong>
            <%= f.text_field :title, label: false, class: 'form-control' %>
          </p>

          <p>
            <strong>Body: </strong>
            <%= f.text_area :body, label: false, class: 'form-control' %>
          </p>

        <% end %>

如何删除在视图上呈现的 authenticity_token?

将以下内容添加到您的表单中以删除身份验证令牌

:authenticity_token => 假

<%= form_for @bar,:authenticity_token => false do |f| %>