Trix-未定义的方法“ to_key”

时间:2019-08-03 14:25:56

标签: ruby-on-rails trix

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

app / assets / javascripts / admins / categories / categories.js

//= require trix

app / assets / stylesheets / admins / categories / categories.css

*= require trix

CategoryForm

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。

0 个答案:

没有答案