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

时间:2018-02-06 08:43:32

标签: ruby-on-rails ruby form-for

我预先在@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

Screnshot enter image description here

观点代码:

      <%= 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?

1 个答案:

答案 0 :(得分:1)

在表单中添加以下内容以删除身份验证令牌

:authenticity_token =&gt;假

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