Search code examples
ruby-on-railstrix

no toolbar gem trix rails 6.0.3.2 ruby 2.7.1


enter image description hereEmpty Trix gem bar

No visible icons of the Trix bar. I have added into head tag app/views/layouts/application.html.erb

<link rel="stylesheet" type="text/css" href="trix.css">
<script type="text/javascript" src="trix.js"></script>

and added *= require trix into app/assets/stylesheets/application.scss

here is my body code

div class="form-group">
  <%= f.label :body %>
  <%= f.text_area :body, class: 'form-control' %>
  <trix-editor input="post_body"></trix-editor>
</div>

Solution

  • I think an easier way to install the trix editor in a Rails 6 app would be to install it via action text:

    rails action_text:install
    

    I believe this will also install active_storage, but if not, you can also run:

    rails active_storage:install
    

    In your model, you add:

    has_rich_text :body
    

    And in your view:

    <%= f.rich_text_area :body %>
    

    You can remove body from your model, as it is no longer needed there. You also have to add body to your permitted params, but is should already be there since it is in your table.

    You can read more about action_text here.