ruby-on-rails – 我可以使用什么样的wysiwyg编辑器来支持图像上传器的rails 3.1应用程序?

我尝试了这个 editor,但收到了很多错误,可能存在一些编辑器,我可以轻松安装和更新图像.

我的答案:
现在我使用this editor,非常容易安装.

解决方法

我使用带有 gem 'tiny_mce'和载波的tinymce进行图像上传.
我对tinymce的设置如下:

$(function() {
  tinyMCE.init({
    mode: "textareas",editor_deselector: "plain",theme: "advanced",plugins: "advimage,inlinepopups,save,autosave",external_image_list_url: '#{image_list_admin_static_images_url}',relative_urls: false,theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect",theme_advanced_buttons22: "",theme_advanced_buttons3: "",theme_advanced_toolbar_location : "top",theme_advanced_blockformats: "p,h2,h3,h4"
  })
}

重要的部分是我的路线中的image_list_admin_static_images_url:

resources :static_images do
      get :image_list,:on => :collection
end

StaticImagesController中的方法如下所示:

def image_list
    @image_list = "var tinyMCEImageList = #{StaticImage.image_list.to_json}"
    render :js => @image_list
 end

在位于模型中的image_list方法中:

def self.image_list
    all.map{ |im| [im.alt,im.image.url] }
 end

这个设置对我来说非常合适,您需要根据自己的需要进行自定义.希望这会帮助你. TinyMCE是非常好的和强大的所见即所得的编辑器.

正如chech在评论部分中所建议的,以下是如何调整此解决方案以与active_admin一起使用:

要在活动管理员中使用它,只需替换此路由: 匹配“admin / model_name /:id / js_image_list”,:action => “js_image_list”,: controller => “管理/ MODEL_NAME”.然后在活动管理模型文件中创建一个名为js_image_list的操作. tinyMCE.init的配置是:external_image_list_url:“js_image_list”

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...