Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Simple form Rails 6操作文本-表单验证错误_Simple Form_Ruby On Rails 6_Actiontext - Fatal编程技术网

Simple form Rails 6操作文本-表单验证错误

Simple form Rails 6操作文本-表单验证错误,simple-form,ruby-on-rails-6,actiontext,Simple Form,Ruby On Rails 6,Actiontext,我正在为我创建的Web CRUD使用操作文本。表单有两个主要属性: 标题:蒂图罗 内容:康泰多 这是我的表格: <%= simple_form_for(@announcement) do |f| %> <%= f.error_notification %> <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present

我正在为我创建的Web CRUD使用操作文本。表单有两个主要属性:

标题:蒂图罗

内容:康泰多

这是我的表格:

<%= simple_form_for(@announcement) do |f| %>
  <%= f.error_notification %>
  <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>

  <div class="form-inputs">

    <div class="form-group">
      <%= f.input :title, input_html: { class: 'form-control' }, label_html: { class: 'form-label' }, required: false %>
    </div>

    <div class="form-group">
      <label class="form-label"> <%= Announcement.human_attribute_name :cover %></label>
      <%= f.input :cover, label: false, input_html: { class: 'form-control' }, as: :file, label_html: { class: 'form-label' }, required: false %> 
    </div>

    <div class="form-group">
      <label class="form-label"><%= Announcement.human_attribute_name :content %></label>
      <%= f.rich_text_area :content, label_html: { class: 'form-label' }, required: false %>
    </div>

    <div class="form-group">
      <label class="form-label"> <%= Announcement.human_attribute_name :is_active %></label>
      <div class="custom-control custom-switch mr-2">
        <%= f.check_box :is_active, class: 'custom-control-input', id: 'is-active-check' %>
        <label class="custom-control-label" for="is-active-check" />
      </div>
    </div>

  </div> <!-- END FORM INPUTS -->

  <div class="form-actions">
    <%= f.button :button, class: 'btn btn-primary mt-3' %>              
  </div>

<% end %> <!-- END FORM -->
问题:

提交空表单时,标题字段显示预期的验证错误。但是,内容字段(操作文本)没有。空的内容字段会阻止记录被保存(这是可以的),但正如我所说的,它不会在表单中显示错误

请参考以下图片:

问题:


如何显示内容字段的验证错误?

简单表单gem在5.0.2版中增加了对富文本区域的支持

使用此版本,只需编写

<%= f.label :content, as: :rich_text_area %>

而不是

<%= f.rich_text_area :content %>


简单表单将发挥其神奇作用。

富文本区域已被plataformatec人员(简单表单开发人员)公然忽视。看看这个问题,可能会有帮助。
<%= f.rich_text_area :content %>