文件上载字段导致ActionController :: InvalidAuthenticityTokenexception
使用rails 4,并尝试使用simple_form和paperclip将文件字段添加到现有表单。
这是表单的关键部分:
一切正常,除非我实际提交带有上传文件的表单。 然后,我明白了:
ActionController::InvalidAuthenticityToken in EmployeesController#update
我在这做错了什么?
最简单的解决方案就是在表单中添加authenticity_token: true
。 像这样:
<%= form_for @employee, html: { class: 'form-horizontal requires'}, multipart: true, remote: true, authenticity_token: true do |f| %> <%= f.input :avatar %> <% end %>
我遇到了同样的问题。 <%= token_tag form_authenticity_token %>
对我不起作用。
安装gem remotipart
解决了我的问题。 remotipart