I have two forms with option remote: true
; one sends an Ajax request to create
action and the other one sends an Ajax request to destroy
action.
All work fines when JavaScript is enabled, but if I disable JavaScript, then I click, I get this error:
ActionController::InvalidAuthenticityToken PersonsController#create
Why this error is shown, and how can I fix it ?
note: I'm using Rails 4
Update
When I use a normal form without option remote: true
, rails automatically inserts a hidden field for an authentication token, but when I use remote: true
in my form there is no such field in the HTML code. It seems like when there is remote
option, then Rails handles the authentication token differently, so how I can get this to work in both cases?
csrf
token inside in html output. If no, that may be the reason. – Haught