Rails - How to add CSRF Protection to forms created in javascript?

后端 未结 5 1006
悲&欢浪女
悲&欢浪女 2020-12-04 14:37

I\'m using backbone.js and it works great. but the forms I\'m creating as a javascript template lacks the rails csrf protection token. How do I add it to templates I\'m crea

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 15:07

    If you have <%= csrf_meta_tag %> in your layout somewhere and that is accessible to you from the js, then you can access it using $('meta[name="csrf-token"]')

    See http://eunikorn.blogspot.com/2011/07/working-with-backbonejs-in-harmony-with.html for an idea on how to hack in csrf support into each backbone request

提交回复
热议问题