Javascript Rails 3 和富文本编辑器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5885006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails 3 and Rich text editor
提问by Steve Harman
I am building a Rails 3 app with blogging, commenting, and other functionality that require the users to input text.
我正在构建一个带有博客、评论和其他需要用户输入文本的功能的 Rails 3 应用程序。
My question is whether it is a better idea to use a Javascript rich text editor or not. What would be the pros and cons. If it is a recommended approach:
我的问题是使用 Javascript 富文本编辑器是否更好。会有什么好处和坏处。如果这是推荐的方法:
- Which editors are best?
- How do I use them in my Rails forms?
- 哪些编辑器最好?
- 如何在 Rails 表单中使用它们?
thanks in advance,
提前致谢,
Steve
史蒂夫
回答by Shreyas
Most rich text editors for the web use JavaScript. These are some popular ones you could consider
大多数用于 Web 的富文本编辑器都使用 JavaScript。这些是你可以考虑的一些流行的
- jwysiwig
- markitup
- Redactor(This is great jQuery based wysiwyg editor that also has a Rails extension I've linked to below.)
- Bootstrap-wysihtml5(If you're looking for a Twitter Bootstrap style editor)
- 知乎
- 标记
- Redactor(这是一个很棒的基于 jQuery 的所见即所得编辑器,它还有一个我在下面链接到的 Rails 扩展。)
- Bootstrap-wysihtml5(如果您正在寻找 Twitter Bootstrap 样式编辑器)
Of course, you could also consider heavy-weight alternatives like TinyMCE or CKEditor, if your needs are such.
当然,如果你有这样的需求,你也可以考虑重量级的替代品,比如 TinyMCE 或 CKEditor。
Ruby on Rails Solutions
Ruby on Rails 解决方案
If you need to able add images to your textarea through a Ruby on Rails library, such as Paperclipor Carrierwave, you may consider one of these
如果您需要能够通过 Ruby on Rails 库(例如Paperclip或Carrierwave )将图像添加到文本区域,您可以考虑以下之一
The Problem with using a usual JavaScript Editor
使用普通 JavaScript 编辑器的问题
Most javascript editors will prompt for a URL when you try to add an image to your textarea, so if you need to do so, you may have to upload the image elsewhere and provide the editor with the URL.
当您尝试将图像添加到文本区域时,大多数 javascript 编辑器会提示您输入 URL,因此如果您需要这样做,您可能必须将图像上传到其他地方并为编辑器提供 URL。
There is however one JavaScript editor I found, http://nicedit.com/, that does an AJAX upload to http://imageshack.uswhen you add an image. Of course, the images that are served will become totally dependent on imageshack which may or may not work for you. It really depends on your scenario.
然而,我找到了一个 JavaScript 编辑器http://nicedit.com/,当您添加图像时,它会将AJAX 上传到http://imageshack.us。当然,提供的图像将完全依赖于 imagehack,这可能对您有用,也可能不适合。这真的取决于你的场景。
回答by stephenmurdoch
I use CKEditor
我使用CKEditor
I would advise you to install the rails_admingem and follow the instructions in the README to set-up CKEditor
我建议您安装rails_admingem 并按照自述文件中的说明设置 CKEditor
It's really easy to use, looks goodand is regularly maintained
它真的很容易使用,看起来不错并且定期维护
If you prefer not to use rails_admin gem, then you can use one of the many rails ckeditor gems
如果您不想使用 rails_admin gem,那么您可以使用众多rails ckeditor gem 之一
good luck
祝你好运