Invalid Authenticity Token for rails form with a file
ajax, ruby-on-rails-4, ujs
Solution
This is a Rails bug. To work around it, you have two options:
- Set `config.action_view.embed_authenticity_token_in_remote_forms = true` in your `config/application.rb`
- Pass the option `authenticity_token: true` to your `form_for`
Problem
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 %> ```