Invalid Authenticity Token for rails form with a file
Asked Answered
Y

1

7

I'm using UJS to handle a form submit with ajax. The form has a file input in it. I'm getting an invalid authenticity token error from the controller that receives it. Am I forgetting some attribute here either on the form or file tag?

ActionController::InvalidAuthenticityToken

<%= form_for @block, 
    remote: true, 
    html: { id: "userInputForm", class: "form" } do |f| %>
    <%= f.file_field :something_to_replace %>
<% end %>
Yowl answered 10/7, 2014 at 5:57 Comment(0)
C
5

This is a Rails bug. To work around it, you have two options:

  1. Set config.action_view.embed_authenticity_token_in_remote_forms = true in your config/application.rb
  2. Pass the option authenticity_token: true to your form_for
Cloven answered 11/9, 2018 at 20:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.