Rails 4を使用し、simple_formとPaperclipを使用して、既存のフォームにファイルフィールドを追加しようとしています。
フォームの重要な部分は次のとおりです。
<%= simple_form_for(@employee, html: { class: 'form-horizontal requires', multipart: true}, remote: true) do |f| %>
<%= f.input :avatar %>
<% end %>
アップロードされたファイルを使用して実際にフォームを送信しない限り、すべて問題なく動作します。次に、私はこれを取得します:
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