Integrating FCK Editor Plugin in Active Scaffold is very easy
Assuming FCK Editor Plugin is installed in your application.
In controller we need to write the following code to make it work:
Considering the category we have this as usual
active_scaffold :category do |config|
config.label = "Category" # Display page name
config.columns = [:name, :rank, :description] # all fields are taken
list.columns.exclude :description #exclude description column in list
end
In Category_Helper.rb we need to add the following code
#description field is shown in FCK editor format
def description_form_column(record, input_name)
fckeditor_textarea( :record, :description, :toolbarSet => 'Simple', :name=> input_name, :width => "800px", :height => "200px" )
end
#description text is displayed in rich format
def description_column(record)
sanitize(record.description)
end
and we need to copy the “_create_form.rhtml” & “_update_form.rhtml” from ..\vendor\plugins\active_scaffold\frontends\default\views to Views/Category and edit _create_form.rhtml by adding following code to it
Instead of <%= submit_tag as_('Create'), :class => "submit" %>
we add following code
="submit" value="Create" class="submit"
onClick="var oEditor = FCKeditorAPI.GetInstance('record_<%=@record.id%>_<%='description'%>_editor');
document.getElementById('record_<%=@record.id%>_<%='description'%>_editor').value = oEditor.GetXHTML();" />
and the same in _update_form.rhtml just replacing the value “Create” to “Update”
and your code will be working fine.
No comments:
Post a Comment