Yshmarov
Yshmarov

Reputation: 3749

How to use rich_text_area with simple_form in Ruby on Rails 6?

At the moment simple_form does not support ruby on rails 6 action_text with the rich_text_area input field. So at the moment my input field can look like this in posts/_form.html.haml:

= f.label :description
= f.rich_text_area :description
= f.error :description, class: 'text-danger'

How to make it work as = f.input :description and have a rich text area?

Upvotes: 2

Views: 3279

Answers (1)

Yshmarov
Yshmarov

Reputation: 3749

create a file in app/inputs/rich_text_area_input.rb:

class RichTextAreaInput < SimpleForm::Inputs::Base
  def input_html_classes
    super.push('trix-content')
  end

  def input(wrapper_options = nil)
    merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)

    @builder.rich_text_area(attribute_name, merged_input_options)
  end
end

in application.scss:

//simple_form input for rich_text_area hight
trix-editor.form-control {
  height: auto;
}

Now in posts/_form.html.haml you can just do:

= f.input :description, as: :rich_text_area

Althrough hopefully at some point simple_form must add it to master

Source 1: https://github.com/heartcombo/simple_form/issues/1638

Source 2: https://github.com/heartcombo/simple_form/pull/1646

Upvotes: 8

Related Questions