1

我有一个CategoryForm对象,我为它呈现一个表单,我安装了 Trix 编辑器 ( gem 'trix') 让我的用户格式化文本。安装后Trix我得到undefined method 'to_key'. 这是我目前的设置。

应用程序/资产/javascripts/admins/categories/categories.js

//= require trix

应用程序/资产/样式表/管理员/类别/categories.css

*= require trix

类别表格

class CategoryForm
  attr_accessor :short_desc_pl, :short_desc_en, :short_desc_de,
                :long_desc_pl, :long_desc_en, :long_desc_de,
                :resource

  def initialize(params = {})
    @resource = Category.find(params[:id])
    generate_fields
  end

  private

  def generate_fields
    @short_desc_pl = @resource.short_description['pl']
    @short_desc_en = @resource.short_description['en']
    @short_desc_de = @resource.short_description['de']
    @long_desc_pl = @resource.long_description['pl']
    @long_desc_en = @resource.long_description['en']
    @long_desc_de = @resource.long_description['de']
  end
end

形式

<%= form_for category_form, as: 'category', url: admins_category_path(category_form.resource), method: :patch do |form| %>
  
  <table class="table">
    <col>
    <colgroup span="2"></colgroup>
    <colgroup span="2"></colgroup>
    <tr>
      <td rowspan="2"></td>
    </tr>
    <tr>
      <th scope="col">PL</th>
      <th scope="col">EN</th>
      <th scope="col">DE</th>
    </tr>
    <tr>
      <th scope="row">Krótki opis</th>
      <td><%= form.text_field :short_desc_pl, class: 'form-control' %></td>
      <td><%= form.text_field :short_desc_en, class: 'form-control', required: true %></td>
      <td><%= form.text_field :short_desc_de, class: 'form-control', required: true %></td>
    </tr>
    <tr>
      <th scope="row">Długi opis</th>
      <td><%= form.trix_editor :long_desc_pl, size: "20x20", class: 'form-control', required: true %></td>
      <td><%= form.text_area :long_desc_en, size: "20x20", class: 'form-control', required: true %></td>
      <td><%= form.text_area :long_desc_de, size: "20x20", class: 'form-control', required: true %></td>
    </tr>
  </table>
  <div class="actions">
    <%= form.submit 'Zapisz' %>
  </div>
<% end %>

我究竟做错了什么?

更新

我什至改变了我的表格以使用@category

<%= form_for category, as: 'category', url: admins_category_path(category), method: :patch do |form| %>
...

而且我没有收到任何错误,但编辑器根本没有呈现。我正在使用 Webpacker,Rails 5.1。

4

0 回答 0