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

     

  • 相关阅读:
    相对嵌套布局
    转:Android控件属性
    layout_weight属性分析
    Node.js 中文乱码解决
    转:正则表达式30分钟入门
    转: 再谈select, iocp, epoll,kqueue及各种I/O复用机制
    多线程调试
    GDB调试增强篇
    GDB调试
    笔趣阁
  • 原文地址:https://www.cnblogs.com/fanxiaopeng/p/3430793.html
Copyright © 2011-2022 走看看