rails_kindeditor 见这里 https://github.com/Macrow/rails_kindeditor,使用很方便
但是在后台使用的时候每次上传图片就会 session 丢失
看了 post 的参数发现是没有提交 authenticity_token
网上没找到解决方案,没法,只有改js源码了
kindeditor/kindeditor-init.js 是这里定义的 uploadJson: "/kindeditor/upload" ,也就是上传的地址,本想在后面加 ?authenticity_token=xxxx 这样的
但是后面的 kindeditor/plugins/image/image.js 里这样使用了 url : uploadJson + '?dir=image' ,
那么只有改 kindeditor/plugins/image/image.js 了,改成下面这样就ok了
#kindeditor/plugins/image/image.js
url : uploadJson + '?dir=image' + "&" + encodeURIComponent($("[name='csrf-param']").attr("content")) + "=" + encodeURIComponent($("[name='csrf-token']").attr("content")),
ok,就这样解决就好,rails_kindeditor 这个定义 uploadJson 不怎么好,要是定义成 uploadJson: "/kindeditor/upload?" ,image.js 中这样使用 url : uploadJson + '&dir=image' ,这样就好扩展多了
但是在后台使用的时候每次上传图片就会 session 丢失
看了 post 的参数发现是没有提交 authenticity_token
网上没找到解决方案,没法,只有改js源码了
kindeditor/kindeditor-init.js 是这里定义的 uploadJson: "/kindeditor/upload" ,也就是上传的地址,本想在后面加 ?authenticity_token=xxxx 这样的
但是后面的 kindeditor/plugins/image/image.js 里这样使用了 url : uploadJson + '?dir=image' ,
那么只有改 kindeditor/plugins/image/image.js 了,改成下面这样就ok了
#kindeditor/plugins/image/image.js
url : uploadJson + '?dir=image' + "&" + encodeURIComponent($("[name='csrf-param']").attr("content")) + "=" + encodeURIComponent($("[name='csrf-token']").attr("content")),
ok,就这样解决就好,rails_kindeditor 这个定义 uploadJson 不怎么好,要是定义成 uploadJson: "/kindeditor/upload?" ,image.js 中这样使用 url : uploadJson + '&dir=image' ,这样就好扩展多了
网友评论(1):
Macrow
2011/09/19 22:01
我已经在 v0.1.1 里修正了这个问题,谢谢vkill的提醒!!详见:https://github.com/Macrow/rails_kindeditor/issues/1
Pages: 1/1
1
1


