ruby-on-rails – Ruby on Rails 3.1,Ckeditor自定义工具栏.在哪里定义

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Ruby on Rails 3.1,Ckeditor自定义工具栏.在哪里定义前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我用gem来安装ckeditor.因此,项目中没有config.js(实际的gem文件夹中有我不想修改).安装确实在config / initializers文件夹中创建了一个ckeditor.js,它似乎是放置工具栏定义的正确位置.但是我试图让它工作的所有内容都会引发各种语法或方法未找到的错误.有人有这个成功吗?如果是这样,一个快速的例子会非常有帮助.

我目前的ckeditor.js是:

# Use this hook to configure ckeditor
if Object.const_defined?("Ckeditor")
  Ckeditor.setup do |config|

  # ==> ORM configuration
  # Load and configure the ORM. Supports :active_record (default),:mongo_mapper and
  # :mongoid (bson_ext recommended) by default. Other ORMs may be
  # available as additional gems.
  require "ckeditor/orm/active_record"

  # Allowed image file types for upload.
  # Set to nil or [] (empty array) for all file types
  # config.image_file_types = ["jpg","jpeg","png","gif","tiff"]

  # Allowed attachment file types for upload.
  # Set to nil or [] (empty array) for all file types
  # config.attachment_file_types = ["doc","docx","xls","odt","ods","pdf","rar","zip","tar","swf"]
  end
end

解决方法

我和你的问题一样.起初,我跟着 Config rails with asset pipeline,但它对我不起作用.然后我意识到该链接的作者只创建了一种新的工具栏样式.您还需要在视图中调用它.这意味着您需要添加此行
input_html => {:toolbar => 'MyToolbar'}

让它工作.

为了测试config.js是否正常工作,您可以检查网页的来源以查看是否添加了assets / javascripts / ckeditor / config.js.
另一种检查方法是通过取消注释该行来编辑编辑器颜色:config.uiColor =’#AADC6E’.如果编辑器的颜色发生变化则会起作用.

我也犯了一个愚蠢的错误,我将ckeditor js文件包含两次:一次放在application.js中,一次放在layouts / application.html.haml文件中.不知道这是否是问题的根源.你可以试试.

希望这可以帮助.

猜你在找的Ruby相关文章