zoukankan      html  css  js  c++  java
  • rails中ActionController::InvalidAuthenticityToken解决办法

    Ror代码 

    class FooController < ApplicationController  
       protect_from_forgery :except => :index  
      
       # you can disable csrf protection on controller-by-controller basis:  
       skip_before_filter :verify_authenticity_token  
     end  

    第二种: 
    修改配置文件configenvironmentsdevelopment.rb 
    Ror代码 

    # Disable request forgery protection in development environment  
      config.action_controller.allow_forgery_protection = false  


    然后重启服务器 
    第三种: 
    在jquery或form中加入 
    Ruby代码 

    <%= javascript_include_tag "jquery.js" %>
    <%= javascript_include_tag "jquery.dataTables.js" %>
    <script type="text/javascript" charset="utf-8">
                $(document).ready(function() {
                    var oTable = $('#example').dataTable( {
                        "bProcessing": true,        
                        "bServerSide": true,             
                        "sServerMethod": "POST",
                        "sAjaxSource": '/welcome/table_list',
                        "fnServerParams": function ( aoData ) {aoData.push( {                
                            "name": "<%= request_forgery_protection_token %>", 
                            "value": "<%= form_authenticity_token %>" } );}
                    } );
                } );
    </script>

    第三种是通过jquery 的datatable插件,实质上就是ajax请求数据的

    这里推荐使用第三种方法,rails这么做的原因是为了防止CSRF,前2个方法时禁止这个功能

     

  • 相关阅读:
    git 生成公钥与私钥
    Swagger PHP使用指南
    数据库需要支持emoji表情
    Lumen实现用户注册登录认证
    Laraver 框架资料
    php curl请求。header头中添加请求信息
    linux 下看所有用户 及所有组
    瀑布流下滑 发送ajax
    Linux系统中的wc
    Nginx 日志分析及性能排查
  • 原文地址:https://www.cnblogs.com/fanxiaopeng/p/3430793.html
Copyright © 2011-2022 走看看