cro*_*don 25 ruby-on-rails paperclip simple-form
使用rails 4,并尝试使用simple_form和paperclip将文件字段添加到现有表单.
这是表单的关键部分:
<%= simple_form_for(@employee, html: { class: 'form-horizontal requires', multipart: true}, remote: true) do |f| %>
<%= f.input :avatar %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
一切正常,除非我实际提交带有上传文件的表单.然后,我明白了:
ActionController::InvalidAuthenticityToken in EmployeesController#update
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
Wil*_*ckl 20
我遇到了同样的问题.<%= token_tag form_authenticity_token %>不适合我.
安装gem remotipart解决了我的问题.remotipart
Hun*_*ter 20
最简单的解决方案就是添加authenticity_token: true到您的表单中.像这样:
<%= form_for @employee, html: { class: 'form-horizontal requires'}, multipart: true, remote: true, authenticity_token: true do |f| %>
<%= f.input :avatar %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8807 次 |
| 最近记录: |