I'm using best_in_place gem to editing client's info in-place.
My question is, how can I integrate a WYSIWYG Editor for editing this content as HTML? I'm currently using this editor: https://github.com/Nerian/bootstrap-wysihtml5-rails/
I'm not good at javascript and cofeescript, so I'm probably doing something wrong.
My code in view:
<%= best_in_place @client, :info, :type => :textarea, :nil => "Click here to add content!", :html_attrs => { class: "wysihtml5" }, :sanitize => false %>
And clients.js.cofee
$(document).ready ->
# Activating Best In Place
jQuery(".best_in_place").best_in_place()
# Loading editor
$(".wysihtml5").each (i, elem) ->
$(elem).wysihtml5()
Does anyone knows what to do about it?
Thanks
You have to iterate over every element with class "wysihtml5" so it should be this way.
And converted to Coffee with Js2Coffee it should work.
I'm using CK-Editor, which I believe would similar to your wysiwyg Editor case somehow.
Here is an example and solution for that: Long article about how he is switching to this:
http://blog.amps211.com/this-is-me-professing-my-love-for-jquery-and-how-i-got-ckeditor-working-with-jeditable/
files to the editor update http://blog.amps211.com/wp-content/uploads/2009/10/jquery.generateId.js http://blog.amps211.com/wp-content/uploads/2009/10/jquery.jeditable.ckeditor.js
I've been playing with this myself, and it was not obvious to say the least.
This is how I eventually got it working:
You need to call
wysihtml5()
on the textarea element, bound tobest_in_place:activate
event. This is myapplication.js.coffee
:I added the
wysihtml5
css class usinginner_class
option on the helper:Note that I'm using
display_as: :info_html
, since I have that field on the model to store processed html, but you can usedisplay_with: lambda { |v| v.html_safe }
if that is not your case.And now it comes the tricky part: the current version (3.0.3) of
best_in_place
does not play nice withwysihtml5
since the textarea got blurred to be substituted by thecontenteditable iframe
, what in turn made the editable operation to be cancelled. I needed to roll a few modifications to the gem on my own that I hope that got merged (you can see the full discussion here), but in the meanwhile you can use my fork. If you do that, then you need to provide your view helper this extra option:skip_blur: true
.Try like this, inner_class: "wysihtml5" if present activate WisiHTML5 editor, buttons 'Save' and 'Cancel' must be present (default event handler disabled for correct work)
In show.html.erb:
In coffee script file:
In show.json.jbuilder:
It could be a simple indentation issue of coffeescript. Just indent the lines below $(document).ready -> by a tab.
To validate further, copy your code in the coffeescript frame @ http://js2coffee.org/: the resulting javascript should look like this:-
That is, the plugins should be called after the dom is loaded.