症状:提示“illegal character”错误,上传失败

原因:Chrome, Firefox, Safari等浏览器本身支持XHR形式的文件上传,但IE不支持,于是Jquery-Fileupload自动在页面添加隐藏的iframe,于是在上传文件时造成 CSRF token 无法传递。

解决:

在View层添加:

1
2
3
4
5
6
7
8
9
10
11
12
  <script>
        $('#fileupload').fileupload();
  </script>
  <!--[if IE]>
    <script>
      $('#fileupload').bind('fileuploadsend', function(event, data) {
        auth_token = $('meta[name="csrf-token"]').attr('content');
        data.url = data.url + '?authenticity_token=' + encodeURIComponent(auth_token);
        $.blueimpUI.fileupload.prototype.options.send.call(this, event, data);
      });
    </script>
  <![endif]-->

同时在controller里添加:

1
2
3
4
5
  format.html {
    render :json => [@episode.to_jq_upload].to_json,
    :content_type => 'text/plain',
    :layout => false
  }

在ActiveAdmin下自定义filter

rails4之后,之前的`model`里加入`search_methods :filter_name`的做法已经失效,需修改为:``` ruby class PromoCode (ids) { with_tags(ids) } def self. …… Continue reading

Mac上搭建Phonegap环境

Published on October 02, 2014

Rails遗留程序里最常犯的错误(译)

Published on July 23, 2014