Ruby on rails RubyonRails3.1,可编辑自定义工具栏。在何处放置定义
我使用gem安装了ckeditor。因此,项目中没有config.js(实际的gem文件夹中有我不想修改的)。安装确实在config/initializers文件夹中创建了一个ckeditor.js,它似乎是放置工具栏定义的正确位置。但我试图让它工作的每件事都会抛出各种语法或方法未发现的错误。有人在这方面取得了成功吗?如果是这样的话,举个简单的例子会很有帮助 我当前的ckeditor.js是:Ruby on rails RubyonRails3.1,可编辑自定义工具栏。在何处放置定义,ruby-on-rails,ruby-on-rails-3,ckeditor,Ruby On Rails,Ruby On Rails 3,Ckeditor,我使用gem安装了ckeditor。因此,项目中没有config.js(实际的gem文件夹中有我不想修改的)。安装确实在config/initializers文件夹中创建了一个ckeditor.js,它似乎是放置工具栏定义的正确位置。但我试图让它工作的每件事都会抛出各种语法或方法未发现的错误。有人在这方面取得了成功吗?如果是这样的话,举个简单的例子会很有帮助 我当前的ckeditor.js是: # Use this hook to configure ckeditor if Object.con
# 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.js文件中,我的问题与您的相同。起初,我遵循了,但这对我不起作用。然后我意识到链接的作者只创建了一种新样式的工具栏。您还需要在视图中调用它。这意味着您需要添加这一行
input_html => {:toolbar => 'MyToolbar'}
让它发挥作用
为了测试config.js是否正常工作,您可以检查网页的源代码,查看是否添加了assets/javascripts/ckeditor/config.js。
另一种检查方法是通过取消注释此行来编辑编辑器颜色:config.uiColor='#AADC6E'
。如果编辑器的颜色改变,那么它就工作了
我还犯了一个愚蠢的错误,我将ckeditor js文件包含了两次:一次在application.js中,一次在layouts/application.html.haml文件中。不知道这是否是问题的根源。你可以试试
希望这能有所帮助。我对github的评论可能会对您有所帮助。1.在application.js中添加以下内容
//= require ckeditor/ckeditor
//= require_tree ./ckeditor
2.在app/assets/javascript/ckeditor中添加config.js
示例config.js
if(typeof(CKEDITOR) != 'undefined')
{
CKEDITOR.editorConfig = function(config) {
config.uiColor = "#AADC6E";
config.toolbar = [
[ 'Bold', 'Italic', 'Underline', 'Strike' ],
[ 'NumberedList', 'BulletedList', 'HorizontalRule' ],
[ 'Blockquote' ],
[ 'Undo', 'Redo' ],
[ 'insertResolved' ],
[ 'Source' ]
];
}
} else{
console.log("ckeditor not loaded")
}
这是更新的对Rails 4.1的回答,使用ckeditor 4.1.0自定义配置ckeditor工具栏 在您看来,使用simple_form,您需要像以下示例一样配置输入: _FORM.HTML.ERB application.js的配置如下所示,请注意ckeditor和require_树的顺序是重要的 APPLICATION.JS 现在,在您的ckeditor.rb中,您应该取消注释这一行“config.asset_path”,并将路径添加到您之前创建的config.js文件中,该文件为“/assets/ckeditor/” ../CONFIG/INITIALIZERS/CKEDITOR.RB
我希望它有帮助:D 嗯,这就是我认为会起作用的东西,但没有乐趣。不管怎样,谢谢您的尝试这是针对
简单表单的。对于Rails默认设置,它只是最后一个HTML参数中的一个选项,:toolbar=>“MyToolbar”
。这个问题可能会提供有关可编辑内容的更多信息
<%= simple_form_for(@foo) do |f| %>
<%= f.input :bar, as: :ckeditor %>
<%= f.button :submit %>
<% end %>
CKEDITOR.editorConfig = function(config) {
//config.language = 'es'; //this could be any language
config.width = '725';
config.height = '600';
// Filebrowser routes
// The location of an external file browser, that should be launched when "Browse Server" button is pressed.
config.filebrowserBrowseUrl = "/ckeditor/attachment_files";
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Flash dialog.
config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files";
// The location of a script that handles file uploads in the Flash dialog.
config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files";
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Link tab of Image dialog.
config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures";
// The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Image dialog.
config.filebrowserImageBrowseUrl = "/ckeditor/pictures";
// The location of a script that handles file uploads in the Image dialog.
config.filebrowserImageUploadUrl = "/ckeditor/pictures";
// The location of a script that handles file uploads.
config.filebrowserUploadUrl = "/ckeditor/attachment_files";
// You could delete or reorder any of this elements as you wish
config.toolbar_Menu = [
{ name: 'document', items: ['Source', '-', 'Save', 'NewPage', 'DocProps', 'Preview', 'Print', '-', 'Templates'] },
{ name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },
{ name: 'editing', items: ['Find', 'Replace', '-', 'SelectAll', '-', 'SpellChecker', 'Scayt'] },
{ name: 'tools', items: ['Maximize', 'ShowBlocks', '-', 'About'] }, '/',
{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] },
{ name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl'] },
{ name: 'links', items: ['Link', 'Unlink', 'Anchor'] }, '/',
{ name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] },
{ name: 'colors', items: ['TextColor', 'BGColor'] },
{ name: 'insert', items: ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'] }
];
config.toolbar = 'Menu';
return true;
};
//= require jquery
//= require jquery_ujs
//= require ckeditor/init
//= require_tree .
# Use this hook to configure 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"
# Customize ckeditor assets path
# By default: nil
config.asset_path = "/assets/ckeditor/"
end