Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid Authenticity Token for rails form with a file

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 %>
like image 812
Don P Avatar asked Oct 21 '22 05:10

Don P


1 Answers

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
like image 76
Barrett Ingram Avatar answered Oct 27 '22 15:10

Barrett Ingram