Ruby on Rails:CKeditor上传图片的问题 [英] Ruby on Rails: problem getting CKeditor to upload images

查看:395
本文介绍了Ruby on Rails:CKeditor上传图片的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我选择一个文件并点击发送到服务器

When I pick a file and click "Send it to the Server"

我得到错误:

ActionController::InvalidAuthenticityToken in MediasController#new_from_disk

Parameters:

{"upload"=>#<File:/var/folders/Fr/FrWbhcV1HdGpFgn7Lh7OhU+++TI/-Tmp-/RackMultipart20100802-4884-olu0e5-0>,
 "CKEditorFuncNum"=>"42",
 "langCode"=>"en",
 "CKEditor"=>"object_content_body"}



< ckeditor上传器发送我的ruby动作文件,然后我处理它。所以我不需要一个视图关联我的new_from_disk行动(目前不做任何事情)。

from my understanding, the ckeditor uploader sends my ruby action the file, and I handle it then and there. So I don't need a view associated with my new_from_disk action (which currently doesn't do anything).

以下是上传/浏览您已上传内容的文档。没有它帮助我。 http://docs.cksource.com/CKEditor_3.x/Developers_Guide / File_Browser_(Uploader)/ Custom_File_Browser

Here is the documentation for uploading / browsing stuff you already have uploaded. None of it has helped me. http://docs.cksource.com/CKEditor_3.x/Developers_Guide/File_Browser_(Uploader)/Custom_File_Browser

任何人都有任何提示/指南?

any one have any hints / guides?

推荐答案

默认情况下,Rails希望提交用户的真实性令牌,如果没有,则引发异常。这是为了防止CSRF(详情请参阅 Rails API

By default, Rails expects to have the user's authenticity token submitted - and raises an exception if it isn't. This is to protect against CSRF (read more at the Rails API)

每当您使用 form_for 时,Rails会将此真实性令牌添加为

Whenever you use a form_for, Rails will add this authenticity token as a hidden input to get submitted with the form.

由于您未使用 form_for (或其任何衍生词),您需要将此标记显式添加到您提交的参数。您可以使用#{form_authenticity_token} 访问令牌的值。

As you aren't using form_for (or any of its derivatives), you need to explicitly add this token to the parameters you submit. You can access the token's value using #{form_authenticity_token}. How you submit it will depend on CKeditor's API.

或者,您可以针对每个操作禁用验证令牌检查(不是推荐!)。像这样:

Alternatively, you can disable auth token checking on a per action basis (not recommended!) like so:

class MediasController < ApplicationController
  skip_before_filter :verify_authenticity_token, :only => [:new_from_disk]

  ...
end

这篇关于Ruby on Rails:CKeditor上传图片的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆