Ask A Question

Notifications

You’re not receiving notifications from this thread.

Commontator with Trix

Nelson Casanova asked in Gems / Libraries

Good day robots,

I'm trying to implement the Trix editor as the default editor for Commontator's comments.

The default Commontator view is defined as follows in app\views\commontator\comments\_form.html.erb:

<%= form_for([commontator, thread, comment],
             remote: !no_remote) do |f| %>
<div class="comment_form_field">
    <%= f.text_area :body, rows: '7' %>
    <%= javascript_tag('Commontator.initMentions()') if Commontator.mentions_enabled %>
</div>
<% end %>

So I get that I need to replace that text_area for the Trix default tag: <trix-editor input="???"></trix-editor> not sure what to put into the input parameter.

The generated HTML for the above form_for is as follows;

<form class="new_comment" id="new_comment" action="/commontator/threads/1/comments" accept-charset="UTF-8" data-remote="true" method="post">

<div class="comment_form_field">
    <div class="field_with_errors">
        <textarea rows="7" name="comment[body]" id="comment_body" spellcheck="false"></textarea>
    </div>
</div>

<div class="comment_form_actions">
    <input type="submit" name="commit" value="Post Comment" data-disable-with="Post Comment">
    <input type="submit" name="cancel" value="Cancel" data-disable-with="Cancel">
</div>

</form>

Any ideas? cheers!

Reply

I should feel ashamed of myself but I'm gonna go ahead and confess that I should have tried a bit harder.

I changed the text_area to hidden_field and added <trix-editor input="comment_body"></trix-editor> commentbody being the same id as the now hidden field.

Reply

Good Day Nelson, would you be able to share your changes made to Commontator and model changes, if any to make trix editor work? Tried your suggestions above, but wasn't not able to make it work.

Reply

For Rails apps, Commontator is a Ruby gem that offers a customizable and user-friendly commenting mechanism.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.