field editor fix

This commit is contained in:
Andrew Brown 2020-01-03 11:04:55 -06:00
parent 02a0eec548
commit cd3cc2f47c
4 changed files with 14 additions and 6 deletions

View File

@ -27,10 +27,15 @@ class AttributeFieldsController < ContentController
end
if @content.attribute_category_id.nil?
category = current_user.attribute_categories.where(label: content_params[:attribute_category] || content_params[:label]).first_or_initialize.tap do |c|
c.entity_type = params[:entity_type] || content_params[:entity_type]
c.save!
category = current_user.attribute_categories.where(id: content_params[:attribute_category_id]).first
if category.nil?
category = current_user.attribute_categories.where(label: content_params[:attribute_category] || content_params[:label]).first_or_initialize.tap do |c|
c.entity_type = params[:entity_type] || content_params[:entity_type]
c.save!
end
end
@content.attribute_category_id = category.id
end
@ -71,7 +76,8 @@ class AttributeFieldsController < ContentController
:attribute_category,
:name, :field_type,
:label, :description,
:entity_type, :attribute_category_id,
:entity_type,
:attribute_category_id,
:hidden
]
end

View File

@ -23,7 +23,7 @@ module HasAttributes
old_column_source: field[:name],
user: user,
field_type: field[:field_type].presence || "text_area",
label: field[:label].presence || 'Untitled field'
label: field[:label].presence || 'Untitled field'
)
af_field
end if details.key?(:attributes)

View File

@ -2,6 +2,7 @@ class AttributeCategory < ApplicationRecord
acts_as_paranoid
validates :name, presence: true
# validates :entity_type, presence: true # todo turn this on, but check prod data for exceptions first
belongs_to :user
has_many :attribute_fields, dependent: :destroy

View File

@ -29,7 +29,8 @@
<div class="collapsible-body">
<%= form_for(category.attribute_fields.build, method: :post) do |f| %>
<%# todo the following line shouldn't be necessary %>
<%= f.hidden_field :category_id, value: category.id %>
<%= f.hidden_field :attribute_category_id, value: category.id %>
<div class="row">
<div class="input-field col s12">
<%= f.text_area :label, class: 'materialize-textarea js-field-input' %>