FCKEditorというWYSIWYGエディタをRuby on Railsアプリ上で使う方法
1.FCKEditorをダウンロード
http://www.fckeditor.netから最新版のFCKEditorをダウンロードし、展開します。
展開したファイル及びフォルダのうち、下記のものをpublic/javascriptsフォルダにコピーします。
/editor/
fckconfig.js
fckeditor.js
fckstyles.xml
fcktemplates.xml
2.fckeditor.jsの編集
fckeditor.jsファイルを開き、this.BasePathを'/javascripts/'に書き換える
// FCKeditor Class
var FCKeditor = function( instanceName, width, height, toolbarSet, value )
{
// Properties
this.InstanceName = instanceName ;
this.Width = width || '100%' ;
this.Height = height || '200' ;
this.ToolbarSet = toolbarSet || 'Default' ;
this.Value = value || '' ;
this.BasePath = '/javascripts/' ;
this.CheckBrowser = true ;
this.DisplayErrors = true ;
3.fckeditor.jsをインクルードする
headタグ内にjavascript_include_tagを使いfckeditor.jsをインクルードします。
<%= javascript_include_tag "fckeditor" %>
4.テキストエリアを置く
テキストエリアは、今までと同じようにActiveViewのtext_areaで配置します。
<%= text_area("object", "method") %>
5.javascriptでテキストエリアをFCKEditorに置き換える
<script type="text/javascript">
window.onload = function()
{
var oFCKeditor = new FCKeditor( 'MyTextarea' ) ;
oFCKeditor.ReplaceTextarea() ;
}
</script>
というのは、こちらを引用しました。