文件上传字段导致 ActionController::InvalidAuthenticityToken 异常 [英] File upload field causing ActionController::InvalidAuthenticityToken exception

查看:45
本文介绍了文件上传字段导致 ActionController::InvalidAuthenticityToken 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 rails 4,并尝试使用 simple_form 和回形针将文件字段添加到现有表单.

Using rails 4, and trying to add a file field to an existing form, using simple_form and paperclip.

这里是表单的关键部分:

Here's the critical part of the form:

<%= simple_form_for(@employee, html: { class: 'form-horizontal requires', multipart: true}, remote: true) do |f| %>

    <%= f.input :avatar %>

<% end %>

一切正常,除非我真的提交了带有上传文件的表单.然后,我明白了:

Everything works ok, unless I actually submit the form with an uploaded file. Then, I get this:

ActionController::InvalidAuthenticityToken in EmployeesController#update

我在这里做错了什么?

推荐答案

最简单的解决方案就是将 authenticity_token: true 添加到您的表单中.像这样:

The simplest solution would just be to add authenticity_token: true to your form. Like this:

<%= form_for @employee, html: { class: 'form-horizontal requires'}, multipart: true, remote: true, authenticity_token: true  do |f| %>
  <%= f.input :avatar %>
<% end %>

这篇关于文件上传字段导致 ActionController::InvalidAuthenticityToken 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆