views:

570

answers:

3

What is the best way to allow for the adding of images and embedding of video in the body:text field of a Ruby on Rails blog.

I understand that I can use an attachment like Paperclip to add a photo to a record but I am wondering how to get images/vids into the actual body of the post.

A: 

One of the classic ways to get embedded stuff like that is to use a WYSIWYG editor like TinyMCE. I've used the plugin TinyMCE and there is also TinyMCE Plus. There are probably plugins for TinyMCE itself to handle some of the embedding stuff.

If you start to allow some tags in your body posts, make sure you are protecting yourself from scripting attacks etc, with something like sanitize to clean up tags you don't want to allow. Make sure you read about XSS and HTML/JavaScript injection.

danivovich
A: 

Try CKEditor for Rails. It is new version of FCK editor with very clean HTML generator. Very easy to embed. All you need to do is replace your input(text-area) helper tag (for content) with another helper tag. Everything is described nicely in project README. You can upload files (pictures) and use them in content directly from CKEditor.

retro
It looks like this is what I need. I installed TinyMCE that danivovich mentioned but didn't allow attachments. The TinyMCE Plus requires attachment_fu (I have paperclip) and also says it might have will_paginate problem. All that said, I can't seem to get CKEditor to install. Do you know of any documentation on installing the gem the gem for this? The git link only has the plugin and either I am entering something wrong in the terminal or it isn't working.
bgadoci
Probably you don't have git installed on your system. Type git --version in your shell. If you don't have git, just install it.Can you write what error are you getting in terminal ?
retro
+1  A: 

I strongly suggest you give WYSIHAT a try. The biggest problem with the editors mentioned above is its bulky size and "hard-to-customize"(ability). The bad code in most of these editors is a big turn-off. WYSIHAT is more like a framework for a WYSIWYG editor. Extremely easy to customize. Easy to configure. And what more.. Its backed by 37signals. What i would appreiciate about TinyMCE is its paste from word feature which preserves the layout. But if not for that one feature i find the rest really bulky.

Please do read this article: http://37signals.com/svn/posts/1330-introducing-wysihat-an-eventually-better-open-source-wysiwyg-editor

Tutorial on using WYSIHAT: Part 1: http://jrmehle.com/2009/01/25/wysiwhat-wysihat-part-1/

Part 2: http://jrmehle.com/2009/02/13/wysiwhat-wysihat-part-2/

And to make your life even easier theres an awesome rails-engine developed by Jeff Kreeftmeijer (80beans.com) for the 37signals WYSIHAT editor: http://github.com/80beans/wysihat-engine

And heres an article by Jeff Kreeftmeijer: http://www.80beans.com/2009/10/01/wysihat-engine/

Shripad K
This looks more like what I am looking for and I love 37Signals. I really appreciate all the links. From the looks of it I can install it as a gem, run the generator, and modify the forms. Do you know of an resources about how to add pics with this? I am using paperclip and wonder if it is compatible or how it would work.
bgadoci
Looks like I have it installed successfully. I have two problems that I will list in another post.
bgadoci
as far as Paperclip is concerned i recommend that you check out the Wysihat-engine. It has used paperclip for uploads. Link back your problems in here.
Shripad K
Hey, probably you don't know CKEditor. Give it a try. No messy code, just nice xhtml and you can copy paste from Word (nice code again). Editor is easy to customize. Stop giving out wisdoms without knowledge Paddy !!! It depend on target user group. For typical office user is CKEditor best choice.
retro
@retro: Thank you for your comment. I am humbled. You can use CKEditor and i'll stick with WYSIhat. The people at 37signals are not fools to bring out a framework for a WYSIWIG editor. Think before you ink. I never tried to bog down CKEditor. I do mention "most" of the editors, not all. That may or may not include CKEditor. CKEditor is not a WYSIWIG framework. And that makes a great difference in itself. You want to do micro level customization in CKEditor? Be my guest. If you actually want to know what i am talking about, try WYSIhat first.
Shripad K