attr_json 2.0 causes AttrJson::Type::PolymorphicModel::TypeError in Spina::Pages#show
aseroff opened this issue · 8 comments
Not super familiar with attr_json so I can't really give much insight outside of providing the error, but here's what I get:
AttrJson::Type::PolymorphicModel::TypeError in Spina::Pages#show
This AttrJson::Type::PolymorphicType can only include {Spina::Parts::Alert}, not 'Spina::Parts::Line': {"name"=>"title", "type"=>"Spina::Parts::Line", "title"=>"Title", "content"=>""}
and the line is when rendering the first item in the view.
As mentioned in the Discord, if you are experiencing this error, you can manually pin attr_json to the earlier version (gem 'attr_json', '1.5'
) and be good to go.
I believe you've introduced your own custom Spina part. Can you share how you've registered Spina::Parts::Alert?
under models/spina/parts
# frozen_string_literal: true
# SpinaCMS
module Spina
# Custom parts for Spina
module Parts
# Alert layout part
class Alert < Base
attr_json :alert, :text
end
end
end
and in theme config
theme.layout_parts = ['alert']
and its view partial, where content
is current_spina_account.content.html(:alert)
.container
.alert.alert-warning{role: 'alert'}
%button.close{data: {dismiss: 'alert'}} x
= content
There should be a call to Spina::Parts.register
somewhere.
Whoops, forgot about config/initializers/spina.rb
Rails.application.reloader.to_prepare do
Spina::Part.register(Spina::Parts::Alert)
end
OH just remembered I have a layout part and a custom page part called alert, could this be a namespace collision?
theme.parts = [
{name: 'alert', title: 'Alert', part_type: 'Spina::Parts::Text'},
...
Hm no changed the name of the layout part, error still raised on page part.
Okay, I've kept digging, here's what it looks like. Attr_json is only expecting custom registered parts for repeaters, not default part types?
Here's the page's json_attributes:
{
"name": "features",
"type": "Spina::Parts::Repeater",
"title": "Features",
"content": [
{
"name": "features",
"parts": [
{
"name": "title",
"type": "Spina::Parts::Text",
"title": "Title",
"content": "LIBRARY"
},
...
When I change the type of the first part in the repeater to my custom-registered part (Spina::Parts::Alert
), the error moves down to the next item in the repeater.
@Bramjetten hole in one again! Issue resolved. Thanks!