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个方法时禁止这个功能

     

  • 相关阅读:
    MySQL系列(三) MySQL的约束
    mysql 下载 国内 镜像
    ckeditor
    比较时间
    远程获取文件
    多线程一例
    requests
    json传递对象字典
    pymysql和mysqldb的区别
    sql
  • 原文地址:https://www.cnblogs.com/fanxiaopeng/p/3430793.html
Copyright © 2011-2022 走看看